]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/test/utils/is_cstring.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / test / utils / is_cstring.hpp
CommitLineData
b32b8144
FG
1// (C) Copyright Gennadiy Rozental 2001.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org/libs/test for the library home page.
7//
92f5a8d4
TL
8//! @file
9//! Defines the is_cstring type trait
b32b8144
FG
10// ***************************************************************************
11
12#ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP
13#define BOOST_TEST_UTILS_IS_CSTRING_HPP
14
15// Boost
16#include <boost/mpl/bool.hpp>
17#include <boost/type_traits/is_same.hpp>
18#include <boost/type_traits/decay.hpp>
19#include <boost/type_traits/remove_pointer.hpp>
20#include <boost/type_traits/remove_const.hpp>
21#include <boost/type_traits/add_const.hpp>
22
23#include <boost/test/utils/basic_cstring/basic_cstring_fwd.hpp>
24#include <string>
25
92f5a8d4
TL
26#if defined(BOOST_TEST_STRING_VIEW)
27#include <string_view>
28#endif
29
b32b8144
FG
30//____________________________________________________________________________//
31
32namespace boost {
33namespace unit_test {
34
35// ************************************************************************** //
36// ************** is_cstring ************** //
37// ************************************************************************** //
38
39namespace ut_detail {
40
41template<typename T>
42struct is_cstring_impl : public mpl::false_ {};
43
44template<typename T>
45struct is_cstring_impl<T const*> : public is_cstring_impl<T*> {};
46
47template<typename T>
48struct is_cstring_impl<T const* const> : public is_cstring_impl<T*> {};
49
50template<>
51struct is_cstring_impl<char*> : public mpl::true_ {};
52
53template<>
54struct is_cstring_impl<wchar_t*> : public mpl::true_ {};
55
56template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value >
92f5a8d4 57struct deduce_cstring_transform_impl;
b32b8144
FG
58
59template <typename T, bool is_cstring >
92f5a8d4 60struct deduce_cstring_transform_impl<T&, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
b32b8144
FG
61
62template <typename T, bool is_cstring >
92f5a8d4 63struct deduce_cstring_transform_impl<T const, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
b32b8144
FG
64
65template <typename T>
92f5a8d4 66struct deduce_cstring_transform_impl<T, true> {
b32b8144
FG
67 typedef typename boost::add_const<
68 typename boost::remove_pointer<
69 typename boost::decay<T>::type
70 >::type
71 >::type U;
72 typedef boost::unit_test::basic_cstring<U> type;
73};
74
75template <typename T>
92f5a8d4 76struct deduce_cstring_transform_impl< T, false > {
b32b8144
FG
77 typedef typename
78 boost::remove_const<
79 typename boost::remove_reference<T>::type
80 >::type type;
81};
82
83template <typename T>
92f5a8d4 84struct deduce_cstring_transform_impl< std::basic_string<T, std::char_traits<T> >, false > {
b32b8144
FG
85 typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type;
86};
87
92f5a8d4
TL
88#if defined(BOOST_TEST_STRING_VIEW)
89template <typename T>
90struct deduce_cstring_transform_impl< std::basic_string_view<T, std::char_traits<T> >, false > {
91private:
92 using sv_t = std::basic_string_view<T, std::char_traits<T> > ;
93
94public:
95 using type = stringview_cstring_helper<typename boost::add_const<T>::type, sv_t>;
96};
97#endif
98
b32b8144
FG
99} // namespace ut_detail
100
101template<typename T>
102struct is_cstring : public ut_detail::is_cstring_impl<typename decay<T>::type> {};
103
104template<typename T, bool is_cstring = is_cstring<typename boost::decay<T>::type>::value >
105struct is_cstring_comparable: public mpl::false_ {};
106
107template<typename T>
108struct is_cstring_comparable< T, true > : public mpl::true_ {};
109
110template<typename T>
111struct is_cstring_comparable< std::basic_string<T, std::char_traits<T> >, false > : public mpl::true_ {};
112
92f5a8d4
TL
113#if defined(BOOST_TEST_STRING_VIEW)
114template<typename T>
115struct is_cstring_comparable< std::basic_string_view<T, std::char_traits<T> >, false > : public mpl::true_ {};
116#endif
117
b32b8144
FG
118template<typename T>
119struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : public mpl::true_ {};
120
121template <class T>
92f5a8d4 122struct deduce_cstring_transform {
b32b8144
FG
123 typedef typename
124 boost::remove_const<
125 typename boost::remove_reference<T>::type
126 >::type U;
92f5a8d4 127 typedef typename ut_detail::deduce_cstring_transform_impl<typename boost::decay<U>::type>::type type;
b32b8144
FG
128};
129
130} // namespace unit_test
131} // namespace boost
132
133#endif // BOOST_TEST_UTILS_IS_CSTRING_HPP