mqtt_cpp
string_view.hpp
Go to the documentation of this file.
1 // Copyright Takatoshi Kondo 2016
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #if !defined(MQTT_STRING_VIEW_HPP)
8 #define MQTT_STRING_VIEW_HPP
9 
10 #include <mqtt/namespace.hpp>
11 
12 #ifdef MQTT_STD_STRING_VIEW
13 
14 #include <string_view>
15 
16 namespace MQTT_NS {
17 
18 using std::string_view;
19 
21 
22 } // namespace MQTT_NS
23 
24 #else // MQTT_STD_STRING_VIEW
25 
26 #include <boost/version.hpp>
27 
28 #if !defined(MQTT_NO_BOOST_STRING_VIEW)
29 
30 #if BOOST_VERSION >= 106100
31 
32 #define MQTT_NO_BOOST_STRING_VIEW 0
33 
34 #include <boost/utility/string_view.hpp>
35 #include <boost/container_hash/hash_fwd.hpp>
36 
37 namespace MQTT_NS {
38 
40 
41 template<class CharT, class Traits = std::char_traits<CharT> >
42 using basic_string_view = boost::basic_string_view<CharT, Traits>;
43 
44 } // namespace MQTT_NS
45 
46 #if BOOST_VERSION < 106900
47 namespace boost {
48 template <class charT, class traits>
49 std::size_t hash_value(basic_string_view<charT, traits> s) {
50  return hash_range(s.begin(), s.end());
51 }
52 }
53 
54 #endif // BOOST_VERSION < 106900
55 
56 #else // BOOST_VERSION >= 106100
57 
58 #define MQTT_NO_BOOST_STRING_VIEW 1
59 
60 #include <boost/utility/string_ref.hpp>
61 
62 namespace MQTT_NS {
63 
64 using string_view = boost::string_ref;
65 
66 template<class CharT, class Traits = std::char_traits<CharT> >
67 using basic_string_view = boost::basic_string_ref<CharT, Traits>;
68 
69 } // namespace MQTT_NS
70 
71 #endif // BOOST_VERSION >= 106100
72 
73 
74 #endif // !defined(MQTT_NO_BOOST_STRING_VIEW)
75 
76 #endif // !defined(MQTT_STD_STRING_VIEW)
77 
78 #endif // MQTT_STRING_VIEW_HPP
Definition: any.hpp:27
boost::string_ref string_view
Definition: string_view.hpp:64
boost::basic_string_ref< CharT, Traits > basic_string_view
Definition: string_view.hpp:67
Definition: buffer.hpp:241