Drop dependency on Boost.StaticAssert

This commit is contained in:
Andrzej Krzemienski
2024-10-16 23:26:44 +02:00
parent b2c7f93ead
commit e601f1ef2d
11 changed files with 78 additions and 82 deletions

View File

@ -11,7 +11,7 @@ add_library(boost_optional INTERFACE)
add_library(Boost::optional ALIAS boost_optional) add_library(Boost::optional ALIAS boost_optional)
target_include_directories(boost_optional INTERFACE include) target_include_directories(boost_optional INTERFACE include)
if(NOT CMAKE_VERSION VERSION_LESS "3.19") if(NOT CMAKE_VERSION VERSION_LESS "3.19")
file(GLOB_RECURSE headers include/*.hpp) file(GLOB_RECURSE headers include/*.hpp)
target_sources(boost_optional PRIVATE ${headers}) target_sources(boost_optional PRIVATE ${headers})
endif() endif()
@ -21,7 +21,6 @@ target_link_libraries(boost_optional
Boost::assert Boost::assert
Boost::config Boost::config
Boost::core Boost::core
Boost::static_assert
Boost::throw_exception Boost::throw_exception
Boost::type_traits Boost::type_traits
) )

View File

@ -9,7 +9,6 @@ constant boost_dependencies :
/boost/assert//boost_assert /boost/assert//boost_assert
/boost/config//boost_config /boost/config//boost_config
/boost/core//boost_core /boost/core//boost_core
/boost/static_assert//boost_static_assert
/boost/throw_exception//boost_throw_exception /boost/throw_exception//boost_throw_exception
/boost/type_traits//boost_type_traits ; /boost/type_traits//boost_type_traits ;
@ -22,4 +21,3 @@ explicit
call-if : boost-library optional call-if : boost-library optional
; ;

View File

@ -13,9 +13,10 @@
[heading Boost Release 1.87] [heading Boost Release 1.87]
* *Breaking change.* Dropped support for C++03. C++11 is now the required minimum. * *Breaking change.* Dropped support for C++03. C++11 is now the required minimum; at least some C++11 features.
* Dropped dependency on Boost.Utility. * Dropped dependency on Boost.Utility.
* Dropped dependency on Boost.Predef. * Dropped dependency on Boost.Predef.
* Dropped dependency on Boost.StaticAssert.
* Dropped dependency on Boost.Move. * Dropped dependency on Boost.Move.
* A bit faster implementation of some relational operations. * A bit faster implementation of some relational operations.
* Tags `in_place_init` and `in_place_init_if` become `inline constexpr` and therewith leave smaller footprint in the executable. This addresses [@https://github.com/boostorg/optional/issues/103 issue #103]. * Tags `in_place_init` and `in_place_init_if` become `inline constexpr` and therewith leave smaller footprint in the executable. This addresses [@https://github.com/boostorg/optional/issues/103 issue #103].

View File

@ -29,16 +29,16 @@ template <class From>
void prevent_binding_rvalue() void prevent_binding_rvalue()
{ {
#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES #ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<From>::value, static_assert(boost::is_lvalue_reference<From>::value,
"binding rvalue references to optional lvalue references is disallowed"); "binding rvalue references to optional lvalue references is disallowed");
#endif #endif
} }
template <class T> template <class T>
BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type& forward_reference(T&& r) BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type& forward_reference(T&& r)
{ {
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<T>::value, static_assert(boost::is_lvalue_reference<T>::value,
"binding rvalue references to optional lvalue references is disallowed"); "binding rvalue references to optional lvalue references is disallowed");
return optional_detail::forward<T>(r); return optional_detail::forward<T>(r);
} }
@ -68,8 +68,8 @@ void prevent_assignment_from_false_const_integral()
#ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT #ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
// MSVC compiler without rvalue references: we need to disable the assignment from // MSVC compiler without rvalue references: we need to disable the assignment from
// const integral lvalue reference, as it may be an invalid temporary // const integral lvalue reference, as it may be an invalid temporary
BOOST_STATIC_ASSERT_MSG(!is_const_integral<From>::value, static_assert(!is_const_integral<From>::value,
"binding const lvalue references to integral types is disabled in this compiler"); "binding const lvalue references to integral types is disabled in this compiler");
#endif #endif
#endif #endif
} }

View File

@ -1053,7 +1053,7 @@ class optional
template<class T> template<class T>
class optional<T&&> class optional<T&&>
{ {
BOOST_STATIC_ASSERT_MSG(sizeof(T) == 0, "Optional rvalue references are illegal."); static_assert(sizeof(T) == 0, "Optional rvalue references are illegal.");
} ; } ;
} // namespace boost } // namespace boost
@ -1163,7 +1163,7 @@ template<class CharType, class CharTrait>
std::basic_ostream<CharType, CharTrait>& std::basic_ostream<CharType, CharTrait>&
operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::optional_tag const&) operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::optional_tag const&)
{ {
BOOST_STATIC_ASSERT_MSG(sizeof(CharType) == 0, "If you want to output boost::optional, include header <boost/optional/optional_io.hpp>"); static_assert(sizeof(CharType) == 0, "If you want to output boost::optional, include header <boost/optional/optional_io.hpp>");
return os; return os;
} }

View File

@ -40,9 +40,9 @@ void test_no_bad_assignment()
{ {
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
// this means that type trait `boost::is_assignable` works. // this means that type trait `boost::is_assignable` works.
BOOST_STATIC_ASSERT((boost::is_assignable<optional<bool>&, bool>::value)); static_assert((boost::is_assignable<optional<bool>&, bool>::value), "ERROR");
BOOST_STATIC_ASSERT((boost::is_assignable<optional<bool>&, implicit_bool_conv>::value)); static_assert((boost::is_assignable<optional<bool>&, implicit_bool_conv>::value), "ERROR");
BOOST_STATIC_ASSERT((! boost::is_assignable<optional<bool>&, explicit_bool_conv>::value)); static_assert((! boost::is_assignable<optional<bool>&, explicit_bool_conv>::value), "ERROR");
#endif #endif
} }

View File

@ -28,14 +28,14 @@ struct superconv
{ {
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
template <typename T> template <typename T>
superconv(T&&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); } superconv(T&&) { static_assert(sizeof(T) == 0, "ERROR"); }
#else #else
template <typename T> template <typename T>
superconv(const T&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); } superconv(const T&) { static_assert(sizeof(T) == 0, "ERROR"); }
template <typename T> template <typename T>
superconv( T&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); } superconv( T&) { static_assert(sizeof(T) == 0, "ERROR"); }
#endif #endif
superconv() {} superconv() {}
}; };
@ -52,19 +52,19 @@ void test_optional_optional_T()
{ {
optional<int> oi1 (1), oiN; optional<int> oi1 (1), oiN;
optional< optional<int> > ooi1 (oi1), ooiN(oiN); optional< optional<int> > ooi1 (oi1), ooiN(oiN);
BOOST_TEST(ooi1); BOOST_TEST(ooi1);
BOOST_TEST(*ooi1); BOOST_TEST(*ooi1);
BOOST_TEST_EQ(**ooi1, 1); BOOST_TEST_EQ(**ooi1, 1);
BOOST_TEST(ooiN); BOOST_TEST(ooiN);
BOOST_TEST(!*ooiN); BOOST_TEST(!*ooiN);
} }
int main() int main()
{ {
test_optional_optional_T(); test_optional_optional_T();
test_optional_of_superconverting_T(); test_optional_of_superconverting_T();
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -44,36 +44,36 @@ struct NothrowNone {
#if 0 // these also test type_traits, which are wrong #if 0 // these also test type_traits, which are wrong
void test_noexcept_as_defined() // this is a compile-time test void test_noexcept_as_defined() // this is a compile-time test
{ {
BOOST_STATIC_ASSERT(::boost::is_nothrow_move_constructible<NothrowBoth>::value); static_assert(::boost::is_nothrow_move_constructible<NothrowBoth>::value, "ERROR");
BOOST_STATIC_ASSERT(::boost::is_nothrow_move_assignable<NothrowBoth>::value); static_assert(::boost::is_nothrow_move_assignable<NothrowBoth>::value, "ERROR");
BOOST_STATIC_ASSERT(::boost::is_nothrow_move_constructible<NothrowCtor>::value); static_assert(::boost::is_nothrow_move_constructible<NothrowCtor>::value, "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_assignable<NothrowCtor>::value); static_assert(!::boost::is_nothrow_move_assignable<NothrowCtor>::value, "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_constructible<NothrowAssign>::value); static_assert(!::boost::is_nothrow_move_constructible<NothrowAssign>::value, "ERROR");
BOOST_STATIC_ASSERT(::boost::is_nothrow_move_assignable<NothrowAssign>::value); static_assert(::boost::is_nothrow_move_assignable<NothrowAssign>::value, "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_constructible<NothrowNone>::value); static_assert(!::boost::is_nothrow_move_constructible<NothrowNone>::value, "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_assignable<NothrowNone>::value); static_assert(!::boost::is_nothrow_move_assignable<NothrowNone>::value, "ERROR");
} }
void test_noexcept_on_optional_with_type_traits() // this is a compile-time test void test_noexcept_on_optional_with_type_traits() // this is a compile-time test
{ {
BOOST_STATIC_ASSERT(::boost::is_nothrow_move_constructible<optional<NothrowBoth> >::value); static_assert(::boost::is_nothrow_move_constructible<optional<NothrowBoth> >::value, "ERROR");
BOOST_STATIC_ASSERT(::boost::is_nothrow_move_assignable<optional<NothrowBoth> >::value); static_assert(::boost::is_nothrow_move_assignable<optional<NothrowBoth> >::value, "ERROR");
BOOST_STATIC_ASSERT(BOOST_NOEXCEPT_EXPR(optional<NothrowBoth>())); static_assert(BOOST_NOEXCEPT_EXPR(optional<NothrowBoth>()), "ERROR");
BOOST_STATIC_ASSERT(::boost::is_nothrow_move_constructible<optional<NothrowCtor> >::value); static_assert(::boost::is_nothrow_move_constructible<optional<NothrowCtor> >::value, "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_assignable<optional<NothrowCtor> >::value); static_assert(!::boost::is_nothrow_move_assignable<optional<NothrowCtor> >::value, "ERROR");
BOOST_STATIC_ASSERT(BOOST_NOEXCEPT_EXPR(optional<NothrowCtor>())); static_assert(BOOST_NOEXCEPT_EXPR(optional<NothrowCtor>()), "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_constructible<optional<NothrowAssign> >::value); static_assert(!::boost::is_nothrow_move_constructible<optional<NothrowAssign> >::value, "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_assignable<optional<NothrowAssign> >::value); static_assert(!::boost::is_nothrow_move_assignable<optional<NothrowAssign> >::value, "ERROR");
BOOST_STATIC_ASSERT(BOOST_NOEXCEPT_EXPR(optional<NothrowAssign>())); static_assert(BOOST_NOEXCEPT_EXPR(optional<NothrowAssign>()), "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_constructible<optional<NothrowNone> >::value); static_assert(!::boost::is_nothrow_move_constructible<optional<NothrowNone> >::value, "ERROR");
BOOST_STATIC_ASSERT(!::boost::is_nothrow_move_assignable<optional<NothrowNone> >::value); static_assert(!::boost::is_nothrow_move_assignable<optional<NothrowNone> >::value, "ERROR");
BOOST_STATIC_ASSERT(BOOST_NOEXCEPT_EXPR(optional<NothrowNone>())); static_assert(BOOST_NOEXCEPT_EXPR(optional<NothrowNone>()), "ERROR");
} }
#endif #endif
@ -87,22 +87,22 @@ void test_noexcept_optional_with_operator() // compile-time test
ONxC onxC; ONxC onxC;
ONxA onxA; ONxA onxA;
ONx0 onx0; ONx0 onx0;
BOOST_STATIC_ASSERT( BOOST_NOEXCEPT_EXPR( ONx2() )); static_assert( BOOST_NOEXCEPT_EXPR( ONx2() ), "ERROR");
BOOST_STATIC_ASSERT( BOOST_NOEXCEPT_EXPR( ONx2(std::move(onx2)) )); static_assert( BOOST_NOEXCEPT_EXPR( ONx2(std::move(onx2)) ), "ERROR");
BOOST_STATIC_ASSERT( BOOST_NOEXCEPT_EXPR( onx2 = ONx2() )); static_assert( BOOST_NOEXCEPT_EXPR( onx2 = ONx2() ), "ERROR");
BOOST_STATIC_ASSERT( BOOST_NOEXCEPT_EXPR( ONxC() )); static_assert( BOOST_NOEXCEPT_EXPR( ONxC() ), "ERROR");
BOOST_STATIC_ASSERT( BOOST_NOEXCEPT_EXPR( ONxC(std::move(onxC)) )); static_assert( BOOST_NOEXCEPT_EXPR( ONxC(std::move(onxC)) ), "ERROR");
BOOST_STATIC_ASSERT(!BOOST_NOEXCEPT_EXPR( onxC = ONxC() )); static_assert(!BOOST_NOEXCEPT_EXPR( onxC = ONxC() ), "ERROR");
BOOST_STATIC_ASSERT( BOOST_NOEXCEPT_EXPR( ONxA() )); static_assert( BOOST_NOEXCEPT_EXPR( ONxA() ), "ERROR");
BOOST_STATIC_ASSERT(!BOOST_NOEXCEPT_EXPR( ONxA(std::move(onxA)) )); static_assert(!BOOST_NOEXCEPT_EXPR( ONxA(std::move(onxA)) ), "ERROR");
BOOST_STATIC_ASSERT(!BOOST_NOEXCEPT_EXPR( onxA = ONxA() )); static_assert(!BOOST_NOEXCEPT_EXPR( onxA = ONxA() ), "ERROR");
BOOST_STATIC_ASSERT( BOOST_NOEXCEPT_EXPR( ONx0() )); static_assert( BOOST_NOEXCEPT_EXPR( ONx0() ), "ERROR");
BOOST_STATIC_ASSERT(!BOOST_NOEXCEPT_EXPR( ONx0(std::move(onx0)) )); static_assert(!BOOST_NOEXCEPT_EXPR( ONx0(std::move(onx0)) ), "ERROR");
BOOST_STATIC_ASSERT(!BOOST_NOEXCEPT_EXPR( onx0 = ONx0() )); static_assert(!BOOST_NOEXCEPT_EXPR( onx0 = ONx0() ), "ERROR");
} }
#endif // !defined BOOST_NO_CXX11_NOEXCEPT #endif // !defined BOOST_NO_CXX11_NOEXCEPT
@ -112,5 +112,3 @@ int main()
{ {
return 0; return 0;
} }

View File

@ -66,7 +66,7 @@ int main()
optFs1 = optFs2; optFs1 = optFs2;
// the following still fails although it shouldn't // the following still fails although it shouldn't
//BOOST_STATIC_ASSERT((std::is_copy_constructible<boost::optional<Path>>::value)); //static_assert((std::is_copy_constructible<boost::optional<Path>>::value), "ERROR");
#endif #endif
#endif #endif

View File

@ -26,7 +26,7 @@ int main()
#ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT #ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
test_converting_assignment<const int, const int>(); test_converting_assignment<const int, const int>();
#else #else
BOOST_STATIC_ASSERT_MSG(false, "EXPECTED TEST COMPILE-TIME FAILURE"); static_assert(false, "EXPECTED TEST COMPILE-TIME FAILURE");
#endif #endif
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -21,29 +21,29 @@ using boost::optional;
struct X {}; struct X {};
struct Y {}; struct Y {};
struct Resource struct Resource
{ {
explicit Resource(const X&) {} explicit Resource(const X&) {}
}; };
BOOST_STATIC_ASSERT(( boost::is_constructible<Resource, const X&>::value )); static_assert(( boost::is_constructible<Resource, const X&>::value ), "ERROR");
BOOST_STATIC_ASSERT(( !boost::is_constructible<Resource, const Y&>::value )); static_assert(( !boost::is_constructible<Resource, const Y&>::value ), "ERROR");
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const X&>::value )); static_assert(( boost::is_constructible<optional<Resource>, const X&>::value ), "ERROR");
BOOST_STATIC_ASSERT(( !boost::is_constructible<optional<Resource>, const Y&>::value )); static_assert(( !boost::is_constructible<optional<Resource>, const Y&>::value ), "ERROR");
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS #ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
BOOST_STATIC_ASSERT(( boost::is_constructible< optional< optional<int> >, optional<int> >::value )); static_assert(( boost::is_constructible< optional< optional<int> >, optional<int> >::value ), "ERROR");
BOOST_STATIC_ASSERT(( !boost::is_constructible< optional<int>, optional< optional<int> > >::value )); static_assert(( !boost::is_constructible< optional<int>, optional< optional<int> > >::value ), "ERROR");
BOOST_STATIC_ASSERT(( boost::is_constructible< optional< optional<int> >, const optional<int>& >::value )); static_assert(( boost::is_constructible< optional< optional<int> >, const optional<int>& >::value ), "ERROR");
BOOST_STATIC_ASSERT(( !boost::is_constructible< optional<int>, const optional< optional<int> >& >::value )); static_assert(( !boost::is_constructible< optional<int>, const optional< optional<int> >& >::value ), "ERROR");
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const optional<X>&>::value )); static_assert(( boost::is_constructible<optional<Resource>, const optional<X>&>::value ), "ERROR");
BOOST_STATIC_ASSERT(( !boost::is_constructible<optional<Resource>, const optional<Y>&>::value )); static_assert(( !boost::is_constructible<optional<Resource>, const optional<Y>&>::value ), "ERROR");
#endif #endif
#endif #endif
int main() { } int main() { }