// // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/url // #ifndef BOOST_URL_DETAIL_OPTIONAL_STRING_HPP #define BOOST_URL_DETAIL_OPTIONAL_STRING_HPP #include #include namespace boost { namespace urls { #ifndef BOOST_URL_DOCS struct no_value_t; #endif namespace detail { struct optional_string { string_view s; bool b = false; }; template typename std::enable_if< std::is_convertible::value, optional_string>::type get_optional_string( String const& s) { optional_string r; r.s = s; r.b = true; return r; } template struct is_dereferenceable : std::false_type {}; template struct is_dereferenceable< T, boost::void_t< decltype(*std::declval()) >> : std::true_type {}; template typename std::enable_if< !std::is_convertible::value, optional_string>::type get_optional_string( OptionalString const& opt) { // If this goes off, it means the rule // passed in did not meet the requirements. // Please check the documentation of functions // that call get_optional_string. static_assert( is_dereferenceable::value && std::is_constructible::value && !std::is_convertible::value && std::is_convertible())>::type, string_view>::value, "OptionalString requirements not met"); optional_string r; r.s = opt ? string_view(*opt) : string_view{}; r.b = static_cast(opt); return r; } inline optional_string get_optional_string( std::nullptr_t) { return {}; } inline optional_string get_optional_string( no_value_t const&) { return {}; } } // detail } // urls } // boost #endif