2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_STRING_PARAM_HPP
11 #define BOOST_BEAST_STRING_PARAM_HPP
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/string.hpp>
15 #include <boost/beast/core/static_string.hpp>
16 #include <boost/beast/core/detail/static_ostream.hpp>
17 #include <boost/beast/core/detail/type_traits.hpp>
18 #include <boost/optional.hpp>
23 /** A function parameter which efficiently converts to string.
25 This is used as a function parameter type to allow callers
26 notational convenience: objects other than strings may be
27 passed in contexts where a string is expected. The conversion
28 to string is made using `operator<<` to a non-dynamically
29 allocated static buffer if possible, else to a `std::string`
32 To use it, modify your function signature to accept
33 `string_param` and then extract the string inside the
36 void print(string_param s)
46 boost::optional<detail::static_ostream> os_;
49 typename std::enable_if<
50 std::is_integral<T>::value>::type
54 typename std::enable_if<
55 ! std::is_integral<T>::value &&
56 ! std::is_convertible<T, string_view>::value
64 typename std::enable_if<
65 std::is_integral<T>::value>::type
69 typename std::enable_if<
70 ! std::is_integral<T>::value>::type
78 template<class T0, class... TN>
80 print_n(T0 const&, TN const&...);
82 template<class T0, class T1, class... TN>
84 print(T0 const&, T1 const&, TN const&...);
87 /// Copy constructor (disallowed)
88 string_param(string_param const&) = delete;
90 /// Copy assignment (disallowed)
91 string_param& operator=(string_param const&) = delete;
95 This function constructs a string as if by concatenating
96 the result of streaming each argument in order into an
97 output stream. It is used as a notational convenience
98 at call sites which expect a parameter with the semantics
99 of a @ref string_view.
101 The implementation uses a small, internal static buffer
102 to avoid memory allocations especially for the case where
103 the list of arguments to be converted consists of a single
106 @param args One or more arguments to convert
108 template<class... Args>
109 string_param(Args const&... args);
111 /// Returns the contained string
118 /// Implicit conversion to @ref string_view
119 operator string_view const() const
128 #include <boost/beast/core/impl/string_param.ipp>