2019-12-16 12:23:46 -05:00
|
|
|
//
|
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2020-02-01 13:51:40 -05:00
|
|
|
// Copyright (c) 2019-2020 Krystian Stasiowski (sdkrystian at gmail dot com)
|
2019-12-16 12:23:46 -05:00
|
|
|
//
|
|
|
|
// 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/static_string
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef BOOST_STATIC_STRING_CONFIG_HPP
|
|
|
|
#define BOOST_STATIC_STRING_CONFIG_HPP
|
|
|
|
|
|
|
|
// Are we dependent on Boost?
|
2019-12-16 19:06:34 -05:00
|
|
|
// #define BOOST_STATIC_STRING_STANDALONE
|
2019-12-16 12:23:46 -05:00
|
|
|
|
2019-12-16 17:36:12 -05:00
|
|
|
// Disable exceptions and their associated checks
|
2019-12-26 17:25:40 -05:00
|
|
|
// #define BOOST_STATIC_STRING_NO_EXCEPTIONS
|
2019-12-16 17:36:12 -05:00
|
|
|
|
2019-12-16 23:50:57 -05:00
|
|
|
// Opt-in to the null terminator optimization
|
|
|
|
// #define BOOST_STATIC_STRING_NULL_OPTIMIZATION
|
|
|
|
|
2019-12-16 12:23:46 -05:00
|
|
|
// Can we have deduction guides?
|
2020-02-03 23:00:16 -05:00
|
|
|
#if __cpp_deduction_guides >= 201703L
|
2019-12-16 12:23:46 -05:00
|
|
|
#define BOOST_STATIC_STRING_USE_DEDUCT
|
|
|
|
#endif
|
|
|
|
|
2020-01-03 19:01:34 -05:00
|
|
|
// Include <version> if we can
|
2020-01-03 19:07:10 -05:00
|
|
|
#ifdef __has_include
|
2020-01-03 19:01:34 -05:00
|
|
|
#if __has_include(<version>)
|
|
|
|
#include <version>
|
|
|
|
#endif
|
2020-01-03 19:07:10 -05:00
|
|
|
#endif
|
2020-01-03 19:01:34 -05:00
|
|
|
|
2020-02-02 11:53:21 -05:00
|
|
|
// Can we use __has_builtin?
|
|
|
|
#ifdef __has_builtin
|
|
|
|
#define BOOST_STATIC_STRING_HAS_BUILTIN(arg) __has_builtin(arg)
|
|
|
|
#else
|
|
|
|
#define BOOST_STATIC_STRING_HAS_BUILTIN(arg) 0
|
|
|
|
#endif
|
|
|
|
|
2020-01-03 19:01:34 -05:00
|
|
|
// Can we use is_constant_evaluated?
|
2020-02-01 21:19:29 -05:00
|
|
|
// Standard version
|
2020-01-03 19:01:34 -05:00
|
|
|
#if __cpp_lib_is_constant_evaluated >= 201811L
|
2020-02-01 21:19:29 -05:00
|
|
|
#define BOOST_STATIC_STRING_IS_CONST_EVAL std::is_constant_evaluated()
|
2020-02-02 11:53:21 -05:00
|
|
|
#elif defined(__clang__) && BOOST_STATIC_STRING_HAS_BUILTIN(__builtin_is_constant_evaluated)
|
2020-02-01 21:19:29 -05:00
|
|
|
// If we have clang version 9+, we can use the intrinsic
|
|
|
|
// While gcc also has this, we don't need it
|
|
|
|
#define BOOST_STATIC_STRING_IS_CONST_EVAL __builtin_is_constant_evaluated()
|
2020-01-03 19:01:34 -05:00
|
|
|
#endif
|
|
|
|
|
2019-12-16 12:23:46 -05:00
|
|
|
// Can we use [[nodiscard]]?
|
|
|
|
#ifdef __has_attribute
|
|
|
|
#if __has_attribute(nodiscard)
|
|
|
|
#define BOOST_STATIC_STRING_NODISCARD [[nodiscard]]
|
|
|
|
#else
|
|
|
|
#define BOOST_STATIC_STRING_NODISCARD
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define BOOST_STATIC_STRING_NODISCARD
|
|
|
|
#endif
|
|
|
|
|
2020-02-03 23:00:16 -05:00
|
|
|
// _MSVC_LANG isn't avaliable until after VS2015
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1910L
|
|
|
|
// The constexpr support in this version is effectively that of
|
|
|
|
// c++11, so we treat it as such
|
|
|
|
#define BOOST_STATIC_STRING_STANDARD_VERSION 201103L
|
|
|
|
#elif defined(_MSVC_LANG)
|
2020-01-03 16:06:12 -05:00
|
|
|
// MSVC doesn't define __cplusplus by default
|
|
|
|
#define BOOST_STATIC_STRING_STANDARD_VERSION _MSVC_LANG
|
|
|
|
#else
|
|
|
|
#define BOOST_STATIC_STRING_STANDARD_VERSION __cplusplus
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BOOST_STATIC_STRING_STANDARD_VERSION > 201703L
|
2020-02-01 21:19:29 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP20
|
|
|
|
#define BOOST_STATIC_STRING_CPP17
|
|
|
|
#define BOOST_STATIC_STRING_CPP14
|
|
|
|
#define BOOST_STATIC_STRING_CPP11
|
2019-12-16 12:23:46 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP20_CONSTEXPR constexpr
|
|
|
|
#define BOOST_STATIC_STRING_CPP17_CONSTEXPR constexpr
|
|
|
|
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR constexpr
|
|
|
|
#define BOOST_STATIC_STRING_CPP11_CONSTEXPR constexpr
|
2020-01-03 16:06:12 -05:00
|
|
|
#elif BOOST_STATIC_STRING_STANDARD_VERSION >= 201703L
|
2020-02-01 21:19:29 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP17
|
|
|
|
#define BOOST_STATIC_STRING_CPP14
|
|
|
|
#define BOOST_STATIC_STRING_CPP11
|
2019-12-16 12:23:46 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP20_CONSTEXPR
|
|
|
|
#define BOOST_STATIC_STRING_CPP17_CONSTEXPR constexpr
|
|
|
|
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR constexpr
|
|
|
|
#define BOOST_STATIC_STRING_CPP11_CONSTEXPR constexpr
|
2020-01-03 16:06:12 -05:00
|
|
|
#elif BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L
|
2020-02-01 21:19:29 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP14
|
|
|
|
#define BOOST_STATIC_STRING_CPP11
|
2019-12-16 12:23:46 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP20_CONSTEXPR
|
|
|
|
#define BOOST_STATIC_STRING_CPP17_CONSTEXPR
|
|
|
|
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR constexpr
|
|
|
|
#define BOOST_STATIC_STRING_CPP11_CONSTEXPR constexpr
|
|
|
|
#else
|
2020-02-01 21:19:29 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP11
|
2019-12-16 12:23:46 -05:00
|
|
|
#define BOOST_STATIC_STRING_CPP20_CONSTEXPR
|
|
|
|
#define BOOST_STATIC_STRING_CPP17_CONSTEXPR
|
|
|
|
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
|
|
|
#define BOOST_STATIC_STRING_CPP11_CONSTEXPR constexpr
|
|
|
|
#endif
|
|
|
|
|
2019-12-16 17:36:12 -05:00
|
|
|
#ifdef BOOST_STATIC_STRING_NO_EXCEPTIONS
|
2020-01-31 15:30:17 -05:00
|
|
|
#define BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT noexcept
|
2019-12-16 17:36:12 -05:00
|
|
|
#define BOOST_STATIC_STRING_THROW_IF(cond, ex)
|
|
|
|
#define BOOST_STATIC_STRING_THROW(ex)
|
2019-12-26 17:22:57 -05:00
|
|
|
#else
|
2020-01-31 15:30:17 -05:00
|
|
|
#define BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT
|
2019-12-16 17:36:12 -05:00
|
|
|
#endif
|
|
|
|
|
2019-12-16 12:23:46 -05:00
|
|
|
// Boost and non-Boost versions of utilities
|
|
|
|
#ifndef BOOST_STATIC_STRING_STANDALONE
|
2019-12-16 17:36:12 -05:00
|
|
|
#ifndef BOOST_STATIC_STRING_THROW_IF
|
|
|
|
#define BOOST_STATIC_STRING_THROW_IF(cond, ex) if (cond) BOOST_THROW_EXCEPTION(ex)
|
|
|
|
#endif
|
2019-12-16 12:23:46 -05:00
|
|
|
#ifndef BOOST_STATIC_STRING_THROW
|
|
|
|
#define BOOST_STATIC_STRING_THROW(ex) BOOST_THROW_EXCEPTION(ex)
|
|
|
|
#endif
|
|
|
|
#ifndef BOOST_STATIC_STRING_STATIC_ASSERT
|
|
|
|
#define BOOST_STATIC_STRING_STATIC_ASSERT(cond, msg) BOOST_STATIC_ASSERT_MSG(cond, msg)
|
|
|
|
#endif
|
|
|
|
#ifndef BOOST_STATIC_STRING_ASSERT
|
|
|
|
#define BOOST_STATIC_STRING_ASSERT(cond) BOOST_ASSERT(cond)
|
|
|
|
#endif
|
|
|
|
#else
|
2019-12-16 17:36:12 -05:00
|
|
|
#ifndef BOOST_STATIC_STRING_THROW_IF
|
|
|
|
#define BOOST_STATIC_STRING_THROW_IF(cond, ex) if (cond) throw ex
|
|
|
|
#endif
|
2019-12-16 12:23:46 -05:00
|
|
|
#ifndef BOOST_STATIC_STRING_THROW
|
|
|
|
#define BOOST_STATIC_STRING_THROW(ex) throw ex
|
|
|
|
#endif
|
|
|
|
#ifndef BOOST_STATIC_STRING_STATIC_ASSERT
|
|
|
|
#define BOOST_STATIC_STRING_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
|
|
|
|
#endif
|
|
|
|
#ifndef BOOST_STATIC_STRING_ASSERT
|
|
|
|
#define BOOST_STATIC_STRING_ASSERT(cond) assert(cond)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 23:42:58 -05:00
|
|
|
#ifndef BOOST_STATIC_STRING_STANDALONE
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
#include <boost/container_hash/hash.hpp>
|
|
|
|
#include <boost/static_assert.hpp>
|
|
|
|
#include <boost/utility/string_view.hpp>
|
|
|
|
#include <boost/throw_exception.hpp>
|
|
|
|
#else
|
|
|
|
#include <cassert>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string_view>
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 17:29:57 -05:00
|
|
|
// Compiler bug prevents constexpr from working with clang 4.x and 5.x
|
2020-02-01 23:42:58 -05:00
|
|
|
// if it is detected, we disable constexpr.
|
2020-02-01 21:19:29 -05:00
|
|
|
#if (BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L && \
|
|
|
|
BOOST_STATIC_STRING_STANDARD_VERSION < 201703L) && \
|
2019-12-17 00:30:59 -05:00
|
|
|
defined(__clang__) && \
|
|
|
|
((__clang_major__ == 4) || (__clang_major__ == 5))
|
2019-12-30 16:44:17 -05:00
|
|
|
// This directive works on clang
|
2020-02-01 17:41:37 -05:00
|
|
|
#warning "C++14 constexpr is not supported in clang 4.x and 5.x due to a compiler bug."
|
2020-02-01 21:19:29 -05:00
|
|
|
#ifdef BOOST_STATIC_STRING_CPP14
|
|
|
|
#undef BOOST_STATIC_STRING_CPP14
|
2019-12-30 16:44:17 -05:00
|
|
|
#endif
|
|
|
|
#undef BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
|
|
|
#define BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
2019-12-16 23:50:57 -05:00
|
|
|
#endif
|
|
|
|
|
2020-02-02 11:43:17 -05:00
|
|
|
// This is for compiler/library configurations
|
2020-02-01 23:18:20 -05:00
|
|
|
// that cannot use the library comparison function
|
|
|
|
// objects at all in constant expresssions. In these
|
|
|
|
// cases, we use whatever will make more constexpr work.
|
2020-02-02 12:15:51 -05:00
|
|
|
#if defined(__clang__) && defined(__GLIBCXX__) && \
|
2020-02-03 23:00:16 -05:00
|
|
|
(__GLIBCXX__ >= 20180726L && __GLIBCXX__ <= 20190812L)
|
2020-02-01 21:19:29 -05:00
|
|
|
#define BOOST_STATIC_STRING_NO_PTR_COMP_FUNCTIONS
|
|
|
|
#endif
|
|
|
|
|
2019-12-16 12:23:46 -05:00
|
|
|
namespace boost {
|
|
|
|
namespace static_string {
|
|
|
|
|
|
|
|
/// The type of `basic_string_view` used by the library
|
|
|
|
template<typename CharT, typename Traits>
|
|
|
|
using basic_string_view =
|
|
|
|
#ifndef BOOST_STATIC_STRING_STANDALONE
|
|
|
|
boost::basic_string_view<CharT, Traits>;
|
|
|
|
#else
|
|
|
|
std::basic_string_view<CharT, Traits>;
|
|
|
|
#endif
|
|
|
|
} // static_string
|
|
|
|
} // boost
|
2020-02-02 12:49:30 -05:00
|
|
|
#endif
|