forked from boostorg/core
Compare commits
10 Commits
feature/ma
...
feature/po
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31117ef800 | ||
|
|
083b41c17e | ||
|
|
a973490f53 | ||
|
|
8cc2fdad76 | ||
|
|
0fb4d92d83 | ||
|
|
76401063a6 | ||
|
|
c4bb59617c | ||
|
|
2d7e036416 | ||
|
|
4a0df827c1 | ||
|
|
59c0fb69f0 |
@@ -11,9 +11,9 @@
|
||||
|
||||
* Added a new [link core.functor `boost/core/functor.hpp`] header with a `functor` class template
|
||||
for wrapping a raw function into a function object class.
|
||||
* Changed [link core.null_deleter `null_deleter`] and [link core.fclose_deleter `fclose_deleter`]
|
||||
definitions so that they don't bring namespace `boost` into argument-dependent lookup in cases
|
||||
like this:
|
||||
* Changed [link core.null_deleter `null_deleter`], [link core.fclose_deleter `fclose_deleter`]
|
||||
and [link.checked_delete checked deleter] definitions so that they don't bring namespace `boost`
|
||||
into argument-dependent lookup in cases like this:
|
||||
```
|
||||
std::unique_ptr< std::FILE, boost::fclose_deleter > p1, p2;
|
||||
swap(p1, p2); // no longer looks for boost::swap as part of ADL
|
||||
|
||||
@@ -70,6 +70,7 @@ criteria for inclusion is that the utility component be:
|
||||
[include null_deleter.qbk]
|
||||
[include fclose_deleter.qbk]
|
||||
[include nvp.qbk]
|
||||
[include pointer_in_range.qbk]
|
||||
[include pointer_traits.qbk]
|
||||
[include quick_exit.qbk]
|
||||
[include ref.qbk]
|
||||
|
||||
80
doc/pointer_in_range.qbk
Normal file
80
doc/pointer_in_range.qbk
Normal file
@@ -0,0 +1,80 @@
|
||||
[/
|
||||
Copyright 2024 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
]
|
||||
|
||||
[section:pointer_in_range pointer_in_range]
|
||||
|
||||
[simplesect Authors]
|
||||
|
||||
* Glen Fernandes
|
||||
|
||||
[endsimplesect]
|
||||
|
||||
[section Overview]
|
||||
|
||||
The header <boost/core/pointer_in_range.hpp> provides the function template
|
||||
`boost::pointer_in_range` to check if a pointer is in a given range. This
|
||||
can be used in constant expressions in C++14 or higher when the compiler has a
|
||||
builtin to support `std::is_constant_evaluated`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Examples]
|
||||
|
||||
The following is an example of an allocator's deallocation function that does
|
||||
nothing if the pointer falls within a small automatically allocated buffer.
|
||||
|
||||
```
|
||||
template<class T, class N>
|
||||
void
|
||||
Allocator<T, N>::deallocate(pointer ptr, size_type)
|
||||
{
|
||||
if (!boost::pointer_in_range(ptr, &buffer_[0], &buffer_[N])) {
|
||||
::operator delete(ptr);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Reference]
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
constexpr bool pointer_in_range(const T* ptr, const T* begin, const T* end);
|
||||
|
||||
} /* boost */
|
||||
```
|
||||
|
||||
[section Functions]
|
||||
|
||||
[variablelist
|
||||
[[`template<class T> constexpr bool pointer_in_range(const T* ptr,
|
||||
const T* begin, T* end);`]
|
||||
[[variablelist
|
||||
[[Returns][`true` if `ptr` is in range `[begin,end)`, otherwise `false`.]]]]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Notes]
|
||||
|
||||
If `boost::pointer_in_range` is not usable in constant expressions the macro
|
||||
`BOOST_CORE_NO_CONSTEXPR_POINTER_IN_RANGE` is defined.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section History]
|
||||
|
||||
Glen Fernandes implemented `pointer_in_range`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
@@ -43,9 +43,17 @@ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
|
||||
#if defined(_STL_DISABLE_DEPRECATED_WARNING)
|
||||
_STL_DISABLE_DEPRECATED_WARNING
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4996)
|
||||
#if defined(__clang__) && defined(__has_warning)
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
# endif
|
||||
#elif defined(_MSC_VER)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996)
|
||||
#elif defined(BOOST_GCC) && BOOST_GCC >= 40600
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
@@ -807,9 +815,15 @@ using allocator_rebind_t = typename allocator_rebind<A, T>::type;
|
||||
|
||||
} /* boost */
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#if defined(__clang__) && defined(__has_warning)
|
||||
# if __has_warning("-Wdeprecated-declarations")
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
#elif defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
#elif defined(BOOST_GCC) && BOOST_GCC >= 40600
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
#if defined(_STL_RESTORE_DEPRECATED_WARNING)
|
||||
_STL_RESTORE_DEPRECATED_WARNING
|
||||
#endif
|
||||
|
||||
@@ -60,6 +60,10 @@ template<class T> inline void checked_array_delete(T * x) BOOST_NOEXCEPT
|
||||
delete [] x;
|
||||
}
|
||||
|
||||
// Block unintended ADL
|
||||
namespace checked_deleters
|
||||
{
|
||||
|
||||
template<class T> struct checked_deleter
|
||||
{
|
||||
typedef void result_type;
|
||||
@@ -83,6 +87,11 @@ template<class T> struct checked_array_deleter
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace checked_deleters
|
||||
|
||||
using checked_deleters::checked_deleter;
|
||||
using checked_deleters::checked_array_deleter;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_CORE_CHECKED_DELETE_HPP
|
||||
|
||||
@@ -392,7 +392,7 @@ public:
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
|
||||
basic_string_view( std::basic_string_view<Ch, std::char_traits<Ch> > const& str ) BOOST_NOEXCEPT: p_( str.data() ), n_( str.size() )
|
||||
BOOST_CONSTEXPR basic_string_view( std::basic_string_view<Ch, std::char_traits<Ch> > const& str ) BOOST_NOEXCEPT: p_( str.data() ), n_( str.size() )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
49
include/boost/core/pointer_in_range.hpp
Normal file
49
include/boost/core/pointer_in_range.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2024 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_CORE_POINTER_IN_RANGE_HPP
|
||||
#define BOOST_CORE_POINTER_IN_RANGE_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <functional>
|
||||
|
||||
#if !defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC >= 1925
|
||||
#define BOOST_CORE_DETAIL_HAS_IS_CONSTEVAL
|
||||
#elif defined(__has_builtin)
|
||||
#if __has_builtin(__builtin_is_constant_evaluated)
|
||||
#define BOOST_CORE_DETAIL_HAS_IS_CONSTEVAL
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CORE_DETAIL_HAS_IS_CONSTEVAL)
|
||||
#define BOOST_CORE_NO_CONSTEXPR_POINTER_IN_RANGE
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
inline BOOST_CONSTEXPR bool
|
||||
pointer_in_range(const T* p, const T* b, const T* e)
|
||||
{
|
||||
#if defined(BOOST_CORE_DETAIL_HAS_IS_CONSTEVAL)
|
||||
if ( __builtin_is_constant_evaluated()) {
|
||||
for (; b != e; ++b) {
|
||||
if (b == p) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return std::less_equal<const T*>()(b, p) && std::less<const T*>()(p, e);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
@@ -39,6 +39,10 @@ compile-fail checked_delete_fail.cpp
|
||||
: $(warnings-as-errors-off) ;
|
||||
compile-fail checked_delete_fail2.cpp
|
||||
: $(warnings-as-errors-off) ;
|
||||
compile-fail checked_deleter_compile_fail_adl.cpp
|
||||
: $(warnings-as-errors-off) ;
|
||||
compile-fail checked_array_deleter_compile_fail_adl.cpp
|
||||
: $(warnings-as-errors-off) ;
|
||||
|
||||
compile ref_ct_test.cpp ;
|
||||
run ref_test.cpp ;
|
||||
@@ -261,6 +265,7 @@ run allocator_destroy_test.cpp ;
|
||||
run allocator_construct_n_test.cpp ;
|
||||
run allocator_destroy_n_test.cpp ;
|
||||
run allocator_traits_test.cpp ;
|
||||
compile allocator_pmr_test.cpp ;
|
||||
|
||||
lib lib_typeid : lib_typeid.cpp : <link>shared:<define>LIB_TYPEID_DYN_LINK=1 ;
|
||||
|
||||
@@ -361,6 +366,9 @@ compile sv_windows_h_test.cpp ;
|
||||
compile-fail sv_nullptr_fail.cpp
|
||||
: $(warnings-as-errors-off) ;
|
||||
|
||||
compile sv_construct_test_cx.cpp ;
|
||||
compile sv_construct_test_cx2.cpp ;
|
||||
|
||||
run span_test.cpp ;
|
||||
run span_types_test.cpp ;
|
||||
run span_constructible_test.cpp ;
|
||||
@@ -408,5 +416,8 @@ run sp_thread_sleep_test.cpp ;
|
||||
run yield_prim_windows_h_test.cpp ;
|
||||
run yield_prim_pthread_cancel_test.cpp : ;
|
||||
|
||||
run pointer_in_range_test.cpp ;
|
||||
compile pointer_in_range_constexpr_test.cpp ;
|
||||
|
||||
use-project /boost/core/swap : ./swap ;
|
||||
build-project ./swap ;
|
||||
|
||||
22
test/allocator_pmr_test.cpp
Normal file
22
test/allocator_pmr_test.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Testing stdlib polymorphic allocators
|
||||
//
|
||||
// Copyright 2024 Braden Ganetsky
|
||||
//
|
||||
// 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
|
||||
//
|
||||
|
||||
#include <boost/core/allocator_access.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifndef BOOST_NO_CXX17_HDR_MEMORY_RESOURCE
|
||||
#include <memory_resource>
|
||||
|
||||
void pmr_allocator_destroy_compiles(std::pmr::polymorphic_allocator<int>& alloc, int* p)
|
||||
{
|
||||
boost::allocator_destroy(alloc, p);
|
||||
}
|
||||
|
||||
#endif // !defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
|
||||
30
test/checked_array_deleter_compile_fail_adl.cpp
Normal file
30
test/checked_array_deleter_compile_fail_adl.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright Andrey Semashev 2024.
|
||||
* 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)
|
||||
*/
|
||||
/*!
|
||||
* \file checked_array_deleter_compile_fail_adl.cpp
|
||||
* \author Andrey Semashev
|
||||
* \date 07.02.2024
|
||||
*
|
||||
* This file tests that \c boost::checked_array_deleter doesn't bring namespace
|
||||
* \c boost into ADL.
|
||||
*/
|
||||
|
||||
#include <boost/core/checked_delete.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
void check_adl(checked_array_deleter< int > const&)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
int main()
|
||||
{
|
||||
// Must not find boost::check_adl
|
||||
check_adl(boost::checked_array_deleter< int >());
|
||||
}
|
||||
30
test/checked_deleter_compile_fail_adl.cpp
Normal file
30
test/checked_deleter_compile_fail_adl.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright Andrey Semashev 2024.
|
||||
* 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)
|
||||
*/
|
||||
/*!
|
||||
* \file checked_deleter_compile_fail_adl.cpp
|
||||
* \author Andrey Semashev
|
||||
* \date 07.02.2024
|
||||
*
|
||||
* This file tests that \c boost::checked_deleter doesn't bring namespace
|
||||
* \c boost into ADL.
|
||||
*/
|
||||
|
||||
#include <boost/core/checked_delete.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
void check_adl(checked_deleter< int > const&)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
int main()
|
||||
{
|
||||
// Must not find boost::check_adl
|
||||
check_adl(boost::checked_deleter< int >());
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
* \date 02.02.2024
|
||||
*
|
||||
* This file tests that \c boost::fclose_deleter doesn't bring namespace
|
||||
* boost into ADL.
|
||||
* \c boost into ADL.
|
||||
*/
|
||||
|
||||
#include <boost/core/fclose_deleter.hpp>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* \date 02.02.2024
|
||||
*
|
||||
* This file tests that \c boost::core::functor doesn't bring namespace
|
||||
* boost::core into ADL.
|
||||
* \c boost::core into ADL.
|
||||
*/
|
||||
|
||||
#include <boost/core/functor.hpp>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* \date 02.02.2024
|
||||
*
|
||||
* This file tests that \c boost::null_deleter doesn't bring namespace
|
||||
* boost into ADL.
|
||||
* \c boost into ADL.
|
||||
*/
|
||||
|
||||
#include <boost/core/null_deleter.hpp>
|
||||
|
||||
31
test/pointer_in_range_constexpr_test.cpp
Normal file
31
test/pointer_in_range_constexpr_test.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright 2024 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/pointer_in_range.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#if !defined(BOOST_CORE_NO_CONSTEXPR_POINTER_IN_RANGE)
|
||||
int a[4] = { 0, 0, 0, 0 };
|
||||
int n = 0;
|
||||
const int b[4] = { 0, 0, 0, 0 };
|
||||
const int m = 0;
|
||||
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(&a[0], &a[1], a + 4));
|
||||
BOOST_STATIC_ASSERT(boost::pointer_in_range(&a[1], &a[1], a + 4));
|
||||
BOOST_STATIC_ASSERT(boost::pointer_in_range(&a[2], &a[1], a + 4));
|
||||
BOOST_STATIC_ASSERT(boost::pointer_in_range(&a[3], &a[1], a + 4));
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(a + 4, &a[1], a + 4));
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(&n, &a[0], &a[3]));
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(&m, &a[0], &a[3]));
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(&b[0], &b[1], b + 4));
|
||||
BOOST_STATIC_ASSERT(boost::pointer_in_range(&b[1], &b[1], b + 4));
|
||||
BOOST_STATIC_ASSERT(boost::pointer_in_range(&b[2], &b[1], b + 4));
|
||||
BOOST_STATIC_ASSERT(boost::pointer_in_range(&b[3], &b[1], b + 4));
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(b + 4, &b[1], b + 4));
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(&n, &b[0], &b[3]));
|
||||
BOOST_STATIC_ASSERT(!boost::pointer_in_range(&m, &b[0], &b[3]));
|
||||
#endif
|
||||
32
test/pointer_in_range_test.cpp
Normal file
32
test/pointer_in_range_test.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2024 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/pointer_in_range.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a[4] = { 0, 0, 0, 0 };
|
||||
int n = 0;
|
||||
const int b[4] = { 0, 0, 0, 0 };
|
||||
const int m = 0;
|
||||
BOOST_TEST(!boost::pointer_in_range(&a[0], &a[1], a + 4));
|
||||
BOOST_TEST(boost::pointer_in_range(&a[1], &a[1], a + 4));
|
||||
BOOST_TEST(boost::pointer_in_range(&a[2], &a[1], a + 4));
|
||||
BOOST_TEST(boost::pointer_in_range(&a[3], &a[1], a + 4));
|
||||
BOOST_TEST(!boost::pointer_in_range(a + 4, &a[1], a + 4));
|
||||
BOOST_TEST(!boost::pointer_in_range(&n, &a[0], &a[3]));
|
||||
BOOST_TEST(!boost::pointer_in_range(&m, &a[0], &a[3]));
|
||||
BOOST_TEST(!boost::pointer_in_range(&b[0], &b[1], b + 4));
|
||||
BOOST_TEST(boost::pointer_in_range(&b[1], &b[1], b + 4));
|
||||
BOOST_TEST(boost::pointer_in_range(&b[2], &b[1], b + 4));
|
||||
BOOST_TEST(boost::pointer_in_range(&b[3], &b[1], b + 4));
|
||||
BOOST_TEST(!boost::pointer_in_range(b + 4, &b[1], b + 4));
|
||||
BOOST_TEST(!boost::pointer_in_range(&n, &b[0], &b[3]));
|
||||
BOOST_TEST(!boost::pointer_in_range(&m, &b[0], &b[3]));
|
||||
return boost::report_errors();
|
||||
}
|
||||
147
test/sv_construct_test_cx.cpp
Normal file
147
test/sv_construct_test_cx.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// Copyright 2021, 2024 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
# include <string_view>
|
||||
#endif
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr boost::core::string_view sv;
|
||||
|
||||
STATIC_ASSERT( sv.data() == nullptr );
|
||||
STATIC_ASSERT( sv.size() == 0 );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr char const* s = "123";
|
||||
|
||||
constexpr boost::core::string_view sv( s, 0 );
|
||||
|
||||
STATIC_ASSERT( sv.data() == s );
|
||||
STATIC_ASSERT( sv.size() == 0 );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr char const* s = "123";
|
||||
|
||||
constexpr boost::core::string_view sv( s, 2 );
|
||||
|
||||
STATIC_ASSERT( sv.data() == s );
|
||||
STATIC_ASSERT( sv.size() == 2 );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr char const* s = "123";
|
||||
|
||||
constexpr boost::core::string_view sv( s, s );
|
||||
|
||||
STATIC_ASSERT( sv.data() == s );
|
||||
STATIC_ASSERT( sv.size() == 0 );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr char const* s = "123";
|
||||
|
||||
constexpr boost::core::string_view sv( s, s + 2 );
|
||||
|
||||
STATIC_ASSERT( sv.data() == s );
|
||||
STATIC_ASSERT( sv.size() == 2 );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
|
||||
|
||||
{
|
||||
constexpr std::string_view str( "123", 3 );
|
||||
|
||||
constexpr boost::core::string_view sv( str );
|
||||
|
||||
STATIC_ASSERT( sv.data() == str.data() );
|
||||
STATIC_ASSERT( sv.size() == str.size() );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
75
test/sv_construct_test_cx2.cpp
Normal file
75
test/sv_construct_test_cx2.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright 2021, 2024 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/core/detail/string_view.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined" )
|
||||
int main() {}
|
||||
|
||||
#elif BOOST_CXX_VERSION < 201703L
|
||||
|
||||
// std::char_traits is not constexpr in C++14
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_CXX_VERSION < 201703L" )
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 70300
|
||||
|
||||
// std::char_traits is not constexpr in libstdc++ 7.2
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_LIBSTDCXX_VERSION < 70300" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr char const* s = "";
|
||||
|
||||
constexpr boost::core::string_view sv( s );
|
||||
|
||||
STATIC_ASSERT( sv.data() == s );
|
||||
STATIC_ASSERT( sv.size() == 0 );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr char const* s = "123";
|
||||
|
||||
constexpr boost::core::string_view sv( s );
|
||||
|
||||
STATIC_ASSERT( sv.data() == s );
|
||||
STATIC_ASSERT( sv.size() == 3 );
|
||||
|
||||
STATIC_ASSERT( sv.begin() == sv.data() );
|
||||
STATIC_ASSERT( sv.end() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.cbegin() == sv.data() );
|
||||
STATIC_ASSERT( sv.cend() == sv.data() + sv.size() );
|
||||
|
||||
STATIC_ASSERT( sv.length() == sv.size() );
|
||||
STATIC_ASSERT( sv.empty() == ( sv.size() == 0 ) );
|
||||
|
||||
STATIC_ASSERT( sv.max_size() == boost::core::string_view::npos );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user