diff --git a/include/boost/static_string/config.hpp b/include/boost/static_string/config.hpp index d3e5139..15e8853 100644 --- a/include/boost/static_string/config.hpp +++ b/include/boost/static_string/config.hpp @@ -62,11 +62,13 @@ // Can we use [[nodiscard]]? // KRYSTIAN TODO: these checks need to be improved -#if defined(__has_attribute) && __has_attribute(nodiscard) +#if defined(__has_attribute) +#if __has_attribute(nodiscard) #define BOOST_STATIC_STRING_NODISCARD [[nodiscard]] #else #define BOOST_STATIC_STRING_NODISCARD #endif +#endif // _MSVC_LANG isn't avaliable until after VS2015 #if defined(_MSC_VER) && _MSC_VER < 1910L diff --git a/test/compile_fail.hpp b/test/compile_fail.hpp index 9a8c279..d0d0dfd 100644 --- a/test/compile_fail.hpp +++ b/test/compile_fail.hpp @@ -1,38 +1,18 @@ #include - #include -#include - namespace boost { namespace static_strings { static_assert(std::is_base_of< - detail::static_string_base_zero<0, char, std::char_traits>, + detail::static_string_base<0, char, std::char_traits>, static_string<0>>::value, "the zero size optimization shall be used for N = 0"); -#ifdef BOOST_STATIC_STRING_USE_NULL_OPTIMIZATION static_assert(std::is_base_of< - detail::static_string_base_null<1, char, std::char_traits>, - static_string<1>>::value, - "the null terminator optimization shall be used for N <= (std::numeric_limits::max)()"); - -static_assert(std::is_base_of< - detail::static_string_base_null<(std::numeric_limits::max)(), char, std::char_traits>, - static_string<(std::numeric_limits::max)()>>::value, - "the null terminator optimization shall be used for N <= std::numeric_limits::max()"); - -static_assert(std::is_base_of< - detail::static_string_base_zero<(std::numeric_limits::max)() + 1, char, std::char_traits>, - static_string<(std::numeric_limits::max)() + 1>>::value, - "the minimum size type optimization shall be used for N > std::numeric_limits::max()"); -#else -static_assert(std::is_base_of< - detail::static_string_base_zero<(std::numeric_limits::max)() + 1, char, std::char_traits>, + detail::static_string_base<(std::numeric_limits::max)() + 1, char, std::char_traits>, static_string<(std::numeric_limits::max)() + 1>>::value, "the minimum size type optimization shall be used for N > 0"); -#endif static_assert(!detail::is_input_iterator::value, "is_input_iterator is incorrect"); static_assert(!detail::is_input_iterator::value, "is_input_iterator is incorrect"); @@ -43,5 +23,5 @@ static_assert(!detail::is_forward_iterator::value, "is_forward_iterator is static_assert(!detail::is_forward_iterator::value, "is_forward_iterator is incorrect"); static_assert(detail::is_forward_iterator::value, "is_forward_iterator is incorrect"); static_assert(!detail::is_forward_iterator>::value, "is_forward_iterator is incorrect"); -} -} \ No newline at end of file +} // boost +} // static_strings \ No newline at end of file diff --git a/test/constexpr_tests.hpp b/test/constexpr_tests.hpp index 20ebff2..5b249f5 100644 --- a/test/constexpr_tests.hpp +++ b/test/constexpr_tests.hpp @@ -7,36 +7,36 @@ // Official repository: https://github.com/boostorg/static_string // -#include #include +#include + +namespace boost { +namespace static_strings { + // char_traits aren't fully constexpr until c++20 #if BOOST_STATIC_STRING_STANDARD_VERSION <= 201703L && BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L struct cxper_char_traits { using char_type = char; using int_type = int; - using state_type = mbstate_t; + using state_type = std::mbstate_t; - static constexpr void assign(char_type& c1, const char_type& c2) noexcept {} - static constexpr bool eq(char_type c1, char_type c2) noexcept { return true; } - static constexpr bool lt(char_type c1, char_type c2) noexcept { return true; } + static constexpr void assign(char_type&, const char_type&) noexcept {} + static constexpr bool eq(char_type, char_type) noexcept { return true; } + static constexpr bool lt(char_type, char_type) noexcept { return true; } - static constexpr int compare(const char_type* s1, const char_type* s2, size_t n) { return 0; } - static constexpr size_t length(const char_type* s) { return 0; } - static constexpr const char_type* find(const char_type* s, size_t n, - const char_type& a) - { - return 0; - } - static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n) { return s1; } - static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n) { return s1; } - static constexpr char_type* assign(char_type* s, size_t n, char_type a) { return s; } + static constexpr int compare(const char_type*, const char_type*, std::size_t) { return 0; } + static constexpr std::size_t length(const char_type*) { return 0; } + static constexpr const char_type* find(const char_type*, std::size_t, const char_type&){ return 0; } + static constexpr char_type* move(char_type* s1, const char_type*, std::size_t) { return s1; } + static constexpr char_type* copy(char_type* s1, const char_type*, std::size_t) { return s1; } + static constexpr char_type* assign(char_type* s, std::size_t, char_type) { return s; } }; #else using cxper_char_traits = std::char_traits; #endif -using cstatic_string = boost::static_strings::basic_static_string<50, char, cxper_char_traits>; +using cstatic_string = basic_static_string<50, char, cxper_char_traits>; inline constexpr @@ -73,55 +73,39 @@ testConstantEvaluation() // element access { auto j = a.at(0); + static_cast(j); } { auto j = a[0]; + static_cast(j); } { auto j = a.front(); + static_cast(j); } { auto j = a.back(); + static_cast(j); } - { - auto j = a.data(); - } - { - auto j = a.c_str(); - } - { - auto j = a.begin(); - } - { - auto j = a.cbegin(); - } - { - auto j = a.end(); - } - { - auto j = a.cend(); - } + a.data(); + a.c_str(); + a.begin(); + a.cbegin(); + a.end(); + a.cend(); // reverse iterators - { - auto j = a.rbegin(); - } - { - auto j = a.crbegin(); - } - { - auto j = a.rend(); - } - { - auto j = a.crend(); - } + a.rbegin(); + a.crbegin(); + a.rend(); + a.crend(); // capacity and size - auto j = cstatic_string().size() + - cstatic_string().empty() + - cstatic_string().length() + - cstatic_string().max_size() + - cstatic_string().capacity(); + cstatic_string().size(); + cstatic_string().empty(); + cstatic_string().length(); + cstatic_string().max_size(); + cstatic_string().capacity(); // clear a.clear(); @@ -263,34 +247,26 @@ testConstantEvaluation() // element access { auto j = a.at(0); + static_cast(j); } { auto j = a[0]; + static_cast(j); } { auto j = a.front(); + static_cast(j); } { auto j = a.back(); + static_cast(j); } - { - auto j = a.data(); - } - { - auto j = a.c_str(); - } - { - auto j = a.begin(); - } - { - auto j = a.cbegin(); - } - { - auto j = a.end(); - } - { - auto j = a.cend(); - } + a.data(); + a.c_str(); + a.begin(); + a.cbegin(); + a.end(); + a.cend(); // reverse iterators //{ @@ -307,11 +283,11 @@ testConstantEvaluation() //} // capacity and size - auto j = cstatic_string().size() + - cstatic_string().empty() + - cstatic_string().length() + - cstatic_string().max_size() + - cstatic_string().capacity(); + cstatic_string().size(); + cstatic_string().empty(); + cstatic_string().length(); + cstatic_string().max_size(); + cstatic_string().capacity(); // clear a.clear(); @@ -453,41 +429,33 @@ testConstantEvaluation() // element access { auto j = a.at(0); + static_cast(j); } { auto j = a[0]; + static_cast(j); } { auto j = a.front(); + static_cast(j); } { auto j = a.back(); + static_cast(j); } - { - auto j = a.data(); - } - { - auto j = a.c_str(); - } - { - auto j = a.begin(); - } - { - auto j = a.cbegin(); - } - { - auto j = a.end(); - } - { - auto j = a.cend(); - } + a.data(); + a.c_str(); + a.begin(); + a.cbegin(); + a.end(); + a.cend(); // capacity and size - auto j = cstatic_string().size() + - cstatic_string().empty() + - cstatic_string().length() + - cstatic_string().max_size() + - cstatic_string().capacity(); + cstatic_string().size(); + cstatic_string().empty(); + cstatic_string().length(); + cstatic_string().max_size(); + cstatic_string().capacity(); // clear a.clear(); @@ -604,4 +572,6 @@ testConstantEvaluation() cstatic_string().max_size() + cstatic_string().capacity(); #endif -} \ No newline at end of file +} +} // static_strings +} // boost \ No newline at end of file diff --git a/test/static_string.cpp b/test/static_string.cpp index 4e001b8..f29ea8d 100644 --- a/test/static_string.cpp +++ b/test/static_string.cpp @@ -10,11 +10,10 @@ // Test that header file is self-contained. #include +#include "constexpr_tests.hpp" +#include "compile_fail.hpp" #include - -#include "constexpr_tests.hpp" - #include #include #include @@ -243,14 +242,14 @@ testTS(Arithmetic value, const char* str_expected = "", const wchar_t* wstr_expe { if (std::is_signed::value) { - return std::strtoll(str.begin(), nullptr, 10) == value && - std::wcstoll(wstr.begin(), nullptr, 10) == value && + return Arithmetic(std::strtoll(str.begin(), nullptr, 10)) == value && + Arithmetic(std::wcstoll(wstr.begin(), nullptr, 10)) == value && (test_expected ? str == str_expected && wstr == wstr_expected : true); } else { - return std::strtoull(str.begin(), nullptr, 10) == value && - std::wcstoull(wstr.begin(), nullptr, 10) == value && + return Arithmetic(std::strtoull(str.begin(), nullptr, 10)) == value && + Arithmetic(std::wcstoull(wstr.begin(), nullptr, 10)) == value && (test_expected ? str == str_expected && wstr == wstr_expected : true); } }