Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:26

0001 //
0002 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/url
0008 //
0009 
0010 #ifndef BOOST_URL_DETAIL_OPTIONAL_STRING_HPP
0011 #define BOOST_URL_DETAIL_OPTIONAL_STRING_HPP
0012 
0013 #include <boost/url/detail/string_view.hpp>
0014 #include <boost/core/detail/string_view.hpp>
0015 
0016 namespace boost {
0017 namespace urls {
0018 
0019 #ifndef BOOST_URL_DOCS
0020 struct no_value_t;
0021 #endif
0022 
0023 namespace detail {
0024 struct optional_string
0025 {
0026     core::string_view s;
0027     bool b = false;
0028 };
0029 
0030 template <class String>
0031 typename std::enable_if<
0032     std::is_convertible<String, core::string_view>::value,
0033     optional_string>::type
0034 get_optional_string(
0035     String const& s)
0036 {
0037     optional_string r;
0038     r.s = s;
0039     r.b = true;
0040     return r;
0041 }
0042 
0043 template <class T, class = void>
0044 struct is_dereferenceable : std::false_type
0045 {};
0046 
0047 template <class T>
0048 struct is_dereferenceable<
0049     T,
0050     void_t<
0051         decltype(*std::declval<T>())
0052         >> : std::true_type
0053 {};
0054 
0055 template <class OptionalString>
0056 typename std::enable_if<
0057     !std::is_convertible<OptionalString, core::string_view>::value,
0058     optional_string>::type
0059 get_optional_string(
0060     OptionalString const& opt)
0061 {
0062     // If this goes off, it means the rule
0063     // passed in did not meet the requirements.
0064     // Please check the documentation of functions
0065     // that call get_optional_string.
0066     static_assert(
0067         is_dereferenceable<OptionalString>::value &&
0068         std::is_constructible<bool, OptionalString>::value &&
0069         !std::is_convertible<OptionalString, core::string_view>::value &&
0070         std::is_convertible<typename std::decay<decltype(*std::declval<OptionalString>())>::type, core::string_view>::value,
0071         "OptionalString requirements not met");
0072     optional_string r;
0073     r.s = opt ? detail::to_sv(*opt) : core::string_view{};
0074     r.b = static_cast<bool>(opt);
0075     return r;
0076 }
0077 
0078 inline
0079 optional_string
0080 get_optional_string(
0081     std::nullptr_t)
0082 {
0083     return {};
0084 }
0085 
0086 inline
0087 optional_string
0088 get_optional_string(
0089     no_value_t const&)
0090 {
0091     return {};
0092 }
0093 
0094 
0095 } // detail
0096 } // urls
0097 } // boost
0098 
0099 #endif