diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d2e049b..d9160c0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -492,13 +492,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}") -check_cxx_source_compiles(" - #include - #include - std::make_index_sequence<0> t; - int main() { return 0; }" - HAVE_STD_INDEX_SEQUENCE -) +include(CheckCXXFeatures) # use BEFORE to ensure local directories are used first, # ahead of system-installed libs diff --git a/CMakeModules/CheckCXXFeatures.cmake b/CMakeModules/CheckCXXFeatures.cmake new file mode 100644 index 00000000..0757da83 --- /dev/null +++ b/CMakeModules/CheckCXXFeatures.cmake @@ -0,0 +1,30 @@ +check_cxx_source_compiles(" + #include + #include + std::make_index_sequence<0> t; + int main() {}" HAVE_STD_INDEX_SEQUENCE +) + +check_cxx_source_compiles(" + #include + std::remove_cv_t t; + int main() {}" HAVE_STD_REMOVE_CV_T +) + +check_cxx_source_compiles(" + #include + std::remove_cvref_t t; + int main() {}" HAVE_STD_REMOVE_CVREF_T +) + +check_cxx_source_compiles(" + #include + std::enable_if_t t; + int main() {}" HAVE_STD_ENABLE_IF_T +) + +check_cxx_source_compiles(" + #include + std::bool_constant t; + int main() {}" HAVE_STD_BOOL_CONSTANT +) \ No newline at end of file diff --git a/simgear/CMakeLists.txt b/simgear/CMakeLists.txt index 6c7cb495..6f8d2933 100644 --- a/simgear/CMakeLists.txt +++ b/simgear/CMakeLists.txt @@ -15,6 +15,7 @@ foreach( mylibfolder nasal/cppbind props serial + std structure threads timing diff --git a/simgear/misc/CMakeLists.txt b/simgear/misc/CMakeLists.txt index c6b0d73a..2931a3b3 100644 --- a/simgear/misc/CMakeLists.txt +++ b/simgear/misc/CMakeLists.txt @@ -9,7 +9,6 @@ set(HEADERS SVGpreserveAspectRatio.hxx argparse.hxx interpolator.hxx - integer_sequence.hxx make_new.hxx sg_dir.hxx sg_hash.hxx @@ -57,10 +56,6 @@ add_executable(test_CSSBorder CSSBorder_test.cxx) add_test(CSSBorder ${EXECUTABLE_OUTPUT_PATH}/test_CSSBorder) target_link_libraries(test_CSSBorder ${TEST_LIBS}) -add_executable(test_integer_sequence integer_sequence_test.cxx) -add_test(integer_sequence ${EXECUTABLE_OUTPUT_PATH}/test_integer_sequence) -target_link_libraries(test_integer_sequence ${TEST_LIBS}) - add_executable(test_tabbed_values tabbed_values_test.cxx) add_test(tabbed_values ${EXECUTABLE_OUTPUT_PATH}/test_tabbed_values) target_link_libraries(test_tabbed_values ${TEST_LIBS}) diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index f09e79c6..59fab718 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -24,17 +24,16 @@ #include "NasalObjectHolder.hxx" #include -#include +#include +#include #include #include #include #include #include -#include #include #include -#include #include @@ -62,10 +61,7 @@ namespace osg } template -inline typename boost::enable_if< - boost::is_pointer, - T ->::type +inline std::enable_if_t::value, T> get_pointer(T ptr) { return ptr; @@ -101,8 +97,8 @@ namespace nasal class GhostMetadata { public: - typedef void(*Deleter)(void*); - typedef std::vector > DestroyList; + using Deleter = void(*)(void*); + using DestroyList = std::vector>; static DestroyList _destroy_list; @@ -154,19 +150,6 @@ namespace nasal }; BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type) - - template - struct reduced_type - { - typedef typename boost::remove_cv< - typename boost::remove_reference::type - >::type type; - }; - - template - struct reduced_is_same: - public boost::is_same::type, T2> - {}; } /** @brief Destroy all ghost queued for deletion. @@ -178,8 +161,8 @@ namespace nasal */ void ghostProcessDestroyList(); - typedef SGSharedPtr MethodHolderPtr; - typedef SGWeakPtr MethodHolderWeakPtr; + using MethodHolderPtr = SGSharedPtr; + using MethodHolderWeakPtr = SGWeakPtr; // Dummy template to create shorter and easy to understand compile errors if // trying to wrap the wrong type as a Ghost. @@ -187,9 +170,10 @@ namespace nasal class Ghost { public: - BOOST_STATIC_ASSERT(("Ghost can only wrap shared pointer!" - && is_strong_ref::value - )); + static_assert( + is_strong_ref::value, + "Ghost can only wrap shared pointer!" + ); static Ghost& init(const std::string& name); static bool isInit(); @@ -209,7 +193,7 @@ namespace nasal * int myMember(); * void doSomethingElse(const nasal::CallContext& ctx); * } - * typedef boost::shared_ptr MyClassPtr; + * using MyClassPtr = boost::shared_ptr; * * std::string myOtherFreeMember(int num); * @@ -235,29 +219,22 @@ namespace nasal * @endcode */ template - class Ghost >::type>: + class Ghost::value>>: public internal::GhostMetadata { - // Shared pointer required for Ghost (no weak pointer!) - BOOST_STATIC_ASSERT((is_strong_ref::value)); - public: - typedef typename T::element_type raw_type; - typedef typename shared_ptr_traits::strong_ref strong_ref; - typedef typename shared_ptr_traits::weak_ref weak_ref; - typedef naRef (raw_type::*member_func_t)(const CallContext&); - typedef naRef (*free_func_t)(raw_type&, const CallContext&); - typedef boost::function getter_t; - typedef boost::function setter_t; - typedef boost::function method_t; - typedef boost::function fallback_getter_t; - typedef boost::function fallback_setter_t; + using raw_type = typename T::element_type; + using strong_ref = typename shared_ptr_traits::strong_ref; + using weak_ref = typename shared_ptr_traits::weak_ref; + using member_func_t = naRef (raw_type::*)(const CallContext&); + using free_func_t = naRef (*)(raw_type&, const CallContext&); + using getter_t = boost::function; + using setter_t = boost::function; + using method_t = boost::function; + using fallback_getter_t = + boost::function; + using fallback_setter_t = + boost::function; template using method_variadic_t = boost::function; @@ -272,8 +249,8 @@ namespace nasal protected: - typedef SGSharedPtr SharedPtr; - typedef SGWeakPtr WeakPtr; + using SharedPtr = SGSharedPtr; + using WeakPtr = SGWeakPtr; method_t _method; @@ -372,7 +349,7 @@ namespace nasal MethodHolderPtr func; }; - typedef std::map MemberMap; + using MemberMap = std::map; /** * Register a new ghost type. @@ -409,19 +386,18 @@ namespace nasal * @endcode */ template - typename boost::enable_if - < - boost::is_base_of, - Ghost - >::type& + std::enable_if_t< + std::is_base_of::value, + Ghost& + > bases() { - BOOST_STATIC_ASSERT - (( - boost::is_base_of::value - )); + static_assert( + std::is_base_of::value, + "Not a base class!" + ); - typedef typename BaseGhost::strong_ref base_ref; + using base_ref = typename BaseGhost::strong_ref; BaseGhost* base = BaseGhost::getSingletonPtr(); base->addDerived( @@ -467,17 +443,16 @@ namespace nasal * @endcode */ template - typename boost::disable_if - < - boost::is_base_of, - Ghost - >::type& + std::enable_if_t< + !std::is_base_of::value, + Ghost& + > bases() { - BOOST_STATIC_ASSERT - (( - boost::is_base_of::raw_type, raw_type>::value - )); + static_assert( + std::is_base_of::raw_type, raw_type>::value, + "Not a base class!" + ); return bases< Ghost >(); } @@ -853,10 +828,10 @@ namespace nasal ) { static_assert( - boost::is_convertible::value, - //|| boost::is_convertible::value + std::is_convertible::value, + //|| std::is_convertible::value // TODO check how to do it with pointer... - "First parameter can not be converted from the Ghost raw_type" + "First parameter can not be converted from the Ghost raw_type!" ); return method(name, method_variadic_t(fn)); @@ -868,11 +843,11 @@ namespace nasal */ template static - typename boost::enable_if_c< - boost::is_same::value - || boost::is_same::value, + std::enable_if_t< + std::is_same::value + || std::is_same::value, naRef - >::type + > makeGhost(naContext c, RefType const& ref_ptr) { strong_ref ref(ref_ptr); @@ -927,13 +902,10 @@ namespace nasal if( !naIsVector(na_parents) ) return strong_ref(); - typedef std::vector naRefs; - naRefs parents = from_nasal(c, na_parents); - for( naRefs::const_iterator parent = parents.begin(); - parent != parents.end(); - ++parent ) + auto parents = from_nasal>(c, na_parents); + for(auto parent: parents) { - strong_ref ref = fromNasal(c, *parent); + strong_ref ref = fromNasal(c, parent); if( get_pointer(ref) ) return ref; } @@ -985,8 +957,9 @@ namespace nasal static naGhostType _ghost_type_strong, //!< Stored as shared pointer _ghost_type_weak; //!< Stored as weak shared pointer - typedef naRef (*to_nasal_t)(naContext, const strong_ref&, bool); - typedef strong_ref (*from_nasal_t)(naContext, naRef); + using to_nasal_t = naRef (*)(naContext, const strong_ref&, bool); + using from_nasal_t = strong_ref (*)(naContext, naRef); + struct DerivedInfo { to_nasal_t to_nasal; @@ -999,7 +972,7 @@ namespace nasal {} }; - typedef std::vector DerivedList; + using DerivedList = std::vector; DerivedList _derived_types; static bool isInstance(naGhostType* ghost_type, bool& is_weak) @@ -1013,13 +986,10 @@ namespace nasal template static - typename boost::enable_if_c< - !is_weak, - RefPtr - >::type + std::enable_if_t getPtr(void* ptr) { - typedef shared_ptr_storage storage_type; + using storage_type = shared_ptr_storage; if( ptr ) return storage_type::template get( static_cast(ptr) @@ -1030,13 +1000,13 @@ namespace nasal template static - typename boost::enable_if_c< + std::enable_if_t< is_weak && supports_weak_ref::value, RefPtr - >::type + > getPtr(void* ptr) { - typedef shared_ptr_storage storage_type; + using storage_type = shared_ptr_storage; if( ptr ) return storage_type::template get( static_cast(ptr) @@ -1047,10 +1017,10 @@ namespace nasal template static - typename boost::enable_if_c< + std::enable_if_t< is_weak && !supports_weak_ref::value, RefPtr - >::type + > getPtr(void* ptr) { return RefPtr(); @@ -1066,10 +1036,10 @@ namespace nasal template static - typename boost::enable_if - < boost::is_polymorphic, - naRef - >::type + std::enable_if_t< + std::is_polymorphic::value, + naRef + > toNasal( naContext c, const typename BaseGhost::strong_ref& base_ref, bool strong ) @@ -1078,10 +1048,10 @@ namespace nasal // Check first if passed pointer can by converted to instance of class // this ghost wraps. - if( !boost::is_same - < typename BaseGhost::raw_type, - typename Ghost::raw_type - >::value + if( !std::is_same< + typename BaseGhost::raw_type, + typename Ghost::raw_type + >::value && dynamic_cast(ptr) != ptr ) return naNil(); @@ -1120,13 +1090,13 @@ namespace nasal template static - typename boost::disable_if - < boost::is_polymorphic, - naRef - >::type - toNasal( naContext c, - const typename BaseGhost::strong_ref& ref, - bool strong ) + std::enable_if_t< + !std::is_polymorphic::value, + naRef + > + toNasal( naContext c, + const typename BaseGhost::strong_ref& ref, + bool strong ) { // For non polymorphic classes there is no possibility to get the actual // dynamic type, therefore we can only use its static type. @@ -1149,7 +1119,7 @@ namespace nasal template getter_t to_getter(Ret (raw_type::*getter)() const) { - typedef typename boost::call_traits::param_type param_type; + using param_type = typename boost::call_traits::param_type; naRef(*to_nasal_)(naContext, param_type) = &to_nasal; // Getter signature: naRef(raw_type&, naContext) @@ -1202,7 +1172,7 @@ namespace nasal */ template static - typename boost::disable_if, naRef>::type + std::enable_if_t::value, naRef> method_invoker ( const boost::function& func, @@ -1218,7 +1188,7 @@ namespace nasal */ template static - typename boost::enable_if, naRef>::type + std::enable_if_t::value, naRef> method_invoker ( const boost::function& func, @@ -1236,10 +1206,10 @@ namespace nasal */ template static - typename boost::disable_if< - internal::reduced_is_same, + std::enable_if_t< + !std::is_same, CallContext>::value, typename from_nasal_ptr::return_type - >::type + > arg_from_nasal(const CallContext& ctx, size_t index) { return ctx.requireArg(index); @@ -1250,19 +1220,21 @@ namespace nasal */ template static - typename boost::enable_if< - internal::reduced_is_same, + std::enable_if_t< + std::is_same, CallContext>::value, typename from_nasal_ptr::return_type - >::type + > arg_from_nasal(const CallContext& ctx, size_t) { // Either const CallContext& or CallContext, non-const reference // does not make sense. - BOOST_STATIC_ASSERT( (!boost::is_same::value) ); + static_assert( + !boost::is_same::value, + "Only const reference and value make sense!"); return ctx; }; - typedef std::unique_ptr GhostPtr; + using GhostPtr = std::unique_ptr; MemberMap _members; fallback_getter_t _fallback_getter; fallback_setter_t _fallback_setter; @@ -1302,13 +1274,10 @@ namespace nasal template static - typename boost::enable_if_c< - !is_weak, - naRef - >::type + std::enable_if_t create(naContext c, const strong_ref& ref_ptr) { - typedef shared_ptr_storage storage_type; + using storage_type = shared_ptr_storage; return naNewGhost2( c, &Ghost::_ghost_type_strong, storage_type::ref(ref_ptr) ); @@ -1316,13 +1285,13 @@ namespace nasal template static - typename boost::enable_if_c< + std::enable_if_t< is_weak && supports_weak_ref::value, naRef - >::type + > create(naContext c, const strong_ref& ref_ptr) { - typedef shared_ptr_storage storage_type; + using storage_type = shared_ptr_storage; return naNewGhost2( c, &Ghost::_ghost_type_weak, storage_type::ref(ref_ptr) ); @@ -1330,10 +1299,10 @@ namespace nasal template static - typename boost::enable_if_c< + std::enable_if_t< is_weak && !supports_weak_ref::value, naRef - >::type + > create(naContext, const strong_ref&) { return naNil(); @@ -1342,7 +1311,7 @@ namespace nasal template static void destroy(void *ptr) { - typedef shared_ptr_storage storage_type; + using storage_type = shared_ptr_storage; storage_type::unref( static_cast(ptr) ); @@ -1477,13 +1446,11 @@ namespace nasal template naGhostType - Ghost >::type> - ::_ghost_type_strong; + Ghost::value>>::_ghost_type_strong; template naGhostType - Ghost >::type> - ::_ghost_type_weak; + Ghost::value>>::_ghost_type_weak; } // namespace nasal @@ -1492,15 +1459,13 @@ namespace nasal * Convert every shared pointer to a ghost. */ template -typename boost::enable_if< - nasal::internal::has_element_type< - typename nasal::internal::reduced_type::type - >, +std::enable_if_t< + nasal::internal::has_element_type>::value, naRef ->::type +> to_nasal_helper(naContext c, T ptr) { - typedef typename nasal::shared_ptr_traits::strong_ref strong_ref; + using strong_ref = typename nasal::shared_ptr_traits::strong_ref; return nasal::Ghost::makeGhost(c, ptr); } @@ -1508,15 +1473,13 @@ to_nasal_helper(naContext c, T ptr) * Convert nasal ghosts/hashes to shared pointer (of a ghost). */ template -typename boost::enable_if< - nasal::internal::has_element_type< - typename nasal::internal::reduced_type::type - >, +std::enable_if_t< + nasal::internal::has_element_type>::value, T ->::type +> from_nasal_helper(naContext c, naRef ref, const T*) { - typedef typename nasal::shared_ptr_traits::strong_ref strong_ref; + using strong_ref = typename nasal::shared_ptr_traits::strong_ref; return T(nasal::Ghost::fromNasalChecked(c, ref)); } @@ -1524,11 +1487,11 @@ from_nasal_helper(naContext c, naRef ref, const T*) * Convert any pointer to a SGReferenced based object to a ghost. */ template -typename boost::enable_if_c< - boost::is_base_of::value - || boost::is_base_of::value, +std::enable_if_t< + std::is_base_of::value + || std::is_base_of::value, naRef ->::type +> to_nasal_helper(naContext c, T* ptr) { return nasal::Ghost >::makeGhost(c, SGSharedPtr(ptr)); @@ -1538,20 +1501,14 @@ to_nasal_helper(naContext c, T* ptr) * Convert nasal ghosts/hashes to pointer (of a SGReferenced based ghost). */ template -typename boost::enable_if_c< - boost::is_base_of< - SGReferenced, - typename boost::remove_pointer::type - >::value - || boost::is_base_of< - SGWeakReferenced, - typename boost::remove_pointer::type - >::value, +std::enable_if_t< + std::is_base_of>::value + || std::is_base_of>::value, T ->::type +> from_nasal_helper(naContext c, naRef ref, const T*) { - typedef SGSharedPtr::type> TypeRef; + using TypeRef = SGSharedPtr>; return T(nasal::Ghost::fromNasalChecked(c, ref)); } @@ -1559,10 +1516,10 @@ from_nasal_helper(naContext c, naRef ref, const T*) * Convert any pointer to a osg::Referenced based object to a ghost. */ template -typename boost::enable_if< - boost::is_base_of, +std::enable_if_t< + std::is_base_of::value, naRef ->::type +> to_nasal_helper(naContext c, T* ptr) { return nasal::Ghost >::makeGhost(c, osg::ref_ptr(ptr)); @@ -1572,13 +1529,13 @@ to_nasal_helper(naContext c, T* ptr) * Convert nasal ghosts/hashes to pointer (of a osg::Referenced based ghost). */ template -typename boost::enable_if< - boost::is_base_of::type>, +std::enable_if_t< + std::is_base_of>::value, T ->::type +> from_nasal_helper(naContext c, naRef ref, const T*) { - typedef osg::ref_ptr::type> TypeRef; + using TypeRef = osg::ref_ptr>; return T(nasal::Ghost::fromNasalChecked(c, ref)); } diff --git a/simgear/nasal/cppbind/detail/nasal_traits.hxx b/simgear/nasal/cppbind/detail/nasal_traits.hxx index 26767d76..17e18ecd 100644 --- a/simgear/nasal/cppbind/detail/nasal_traits.hxx +++ b/simgear/nasal/cppbind/detail/nasal_traits.hxx @@ -20,10 +20,7 @@ #ifndef SG_NASAL_TRAITS_HXX_ #define SG_NASAL_TRAITS_HXX_ -#include -#include -#include -#include +#include // Forward declarations class SGReferenced; @@ -56,12 +53,11 @@ namespace osg namespace nasal { template - struct is_vec2: public boost::integral_constant {}; + struct is_vec2: public std::false_type {}; #define SG_MAKE_TRAIT(templ,type,attr)\ template templ\ - struct attr< type >:\ - public boost::integral_constant {}; + struct attr< type >: public std::true_type {}; SG_MAKE_TRAIT(, SGVec2, is_vec2) SG_MAKE_TRAIT(<>, osg::Vec2b, is_vec2) @@ -75,42 +71,34 @@ SG_MAKE_TRAIT(<>, osg::Vec2s, is_vec2) struct shared_ptr_traits; template - struct is_strong_ref: - public boost::integral_constant - {}; + struct is_strong_ref: public std::false_type {}; template - struct is_weak_ref: - public boost::integral_constant - {}; + struct is_weak_ref: public std::false_type {}; #define SG_MAKE_SHARED_PTR_TRAIT(strong, weak, intrusive)\ template\ struct shared_ptr_traits >\ {\ - typedef strong strong_ref;\ - typedef weak weak_ref;\ - typedef T element_type;\ - typedef boost::integral_constant is_strong;\ - typedef boost::integral_constant is_intrusive;\ + using strong_ref = strong;\ + using weak_ref = weak;\ + using element_type = T;\ + using is_strong = std::true_type;\ + using is_intrusive = std::bool_constant;\ };\ template\ struct shared_ptr_traits >\ {\ - typedef strong strong_ref;\ - typedef weak weak_ref;\ - typedef T element_type;\ - typedef boost::integral_constant is_strong;\ - typedef boost::integral_constant is_intrusive;\ + using strong_ref = strong;\ + using weak_ref = weak;\ + using element_type = T;\ + using is_strong = std::false_type;\ + using is_intrusive = std::bool_constant;\ };\ template\ - struct is_strong_ref >:\ - public boost::integral_constant\ - {};\ + struct is_strong_ref >: public std::true_type {};\ template\ - struct is_weak_ref >:\ - public boost::integral_constant\ - {}; + struct is_weak_ref >: public std::true_type {}; SG_MAKE_SHARED_PTR_TRAIT(SGSharedPtr, SGWeakPtr, true) SG_MAKE_SHARED_PTR_TRAIT(osg::ref_ptr, osg::observer_ptr, true) @@ -119,25 +107,20 @@ SG_MAKE_TRAIT(<>, osg::Vec2s, is_vec2) #undef SG_MAKE_SHARED_PTR_TRAIT template - struct supports_weak_ref: - public boost::integral_constant - {}; + struct supports_weak_ref: public std::true_type {}; template struct supports_weak_ref >: - public boost::integral_constant< - bool, - boost::is_base_of::value - > + public std::bool_constant::value> {}; template struct shared_ptr_storage { - typedef T storage_type; - typedef typename T::element_type element_type; - typedef typename shared_ptr_traits::strong_ref strong_ref; - typedef typename shared_ptr_traits::weak_ref weak_ref; + using storage_type = T; + using element_type = typename T::element_type; + using strong_ref = typename shared_ptr_traits::strong_ref; + using weak_ref = typename shared_ptr_traits::weak_ref; template static storage_type* ref(U ptr) @@ -151,39 +134,30 @@ SG_MAKE_TRAIT(<>, osg::Vec2s, is_vec2) template static - typename boost::enable_if< - boost::is_same, - element_type* - >::type + std::enable_if_t::value, element_type*> get(storage_type* ptr) { return get_pointer(*ptr); } + template static - typename boost::enable_if< - boost::mpl::or_< - boost::is_same, - boost::mpl::and_< - boost::is_same, - supports_weak_ref - > - >, + std::enable_if_t< + std::is_same::value + || (std::is_same::value && supports_weak_ref::value), U - >::type + > get(storage_type* ptr) { return U(*ptr); } + template static - typename boost::enable_if< - boost::mpl::and_< - boost::is_same, - boost::mpl::not_ > - >, + std::enable_if_t< + std::is_same::value && !supports_weak_ref::value, U - >::type + > get(storage_type* ptr) { return U(); @@ -195,46 +169,37 @@ SG_MAKE_TRAIT(<>, osg::Vec2s, is_vec2) template struct intrusive_ptr_storage { - typedef typename T::element_type storage_type; - typedef typename T::element_type element_type; - typedef typename shared_ptr_traits::strong_ref strong_ref; - typedef typename shared_ptr_traits::weak_ref weak_ref; + using storage_type = typename T::element_type; + using element_type = typename T::element_type; + using strong_ref = typename shared_ptr_traits::strong_ref; + using weak_ref = typename shared_ptr_traits::weak_ref; template static - typename boost::enable_if< - boost::is_same, - element_type* - >::type + std::enable_if_t::value, element_type*> get(storage_type* ptr) { return ptr; } + template static - typename boost::enable_if< - boost::mpl::or_< - boost::is_same, - boost::mpl::and_< - boost::is_same, - supports_weak_ref - > - >, + std::enable_if_t< + std::is_same::value + || (std::is_same::value && supports_weak_ref::value), U - >::type + > get(storage_type* ptr) { return U(ptr); } + template static - typename boost::enable_if< - boost::mpl::and_< - boost::is_same, - boost::mpl::not_ > - >, + std::enable_if_t< + std::is_same::value && !supports_weak_ref::value, U - >::type + > get(storage_type* ptr) { return U(); @@ -246,8 +211,8 @@ SG_MAKE_TRAIT(<>, osg::Vec2s, is_vec2) struct shared_ptr_storage >: public internal::intrusive_ptr_storage > { - typedef T storage_type; - typedef T element_type; + using storage_type = T; + using element_type = T; static storage_type* ref(element_type* ptr) { @@ -265,8 +230,8 @@ SG_MAKE_TRAIT(<>, osg::Vec2s, is_vec2) struct shared_ptr_storage >: public internal::intrusive_ptr_storage > { - typedef T storage_type; - typedef T element_type; + using storage_type = T; + using element_type = T; static storage_type* ref(element_type* ptr) diff --git a/simgear/simgear_config_cmake.h.in b/simgear/simgear_config_cmake.h.in index b68991da..c3668638 100644 --- a/simgear/simgear_config_cmake.h.in +++ b/simgear/simgear_config_cmake.h.in @@ -16,6 +16,10 @@ #cmakedefine HAVE_MKDTEMP #cmakedefine HAVE_AL_EXT_H #cmakedefine HAVE_STD_INDEX_SEQUENCE +#cmakedefine HAVE_STD_REMOVE_CV_T +#cmakedefine HAVE_STD_REMOVE_CVREF_T +#cmakedefine HAVE_STD_ENABLE_IF_T +#cmakedefine HAVE_STD_BOOL_CONSTANT #cmakedefine GCC_ATOMIC_BUILTINS_FOUND diff --git a/simgear/std/CMakeLists.txt b/simgear/std/CMakeLists.txt new file mode 100644 index 00000000..ad47054e --- /dev/null +++ b/simgear/std/CMakeLists.txt @@ -0,0 +1,21 @@ +include (SimGearComponent) + +set(HEADERS + integer_sequence.hxx + type_traits.hxx +) + +set(SOURCES +) + +simgear_component(std std "${SOURCES}" "${HEADERS}") + +if(ENABLE_TESTS) + add_executable(test_integer_sequence integer_sequence_test.cxx) + add_test(integer_sequence ${EXECUTABLE_OUTPUT_PATH}/test_integer_sequence) + target_link_libraries(test_integer_sequence ${TEST_LIBS}) + + add_executable(test_type_traits type_traits_test.cxx) + add_test(type_traits ${EXECUTABLE_OUTPUT_PATH}/test_type_traits) + target_link_libraries(test_type_traits ${TEST_LIBS}) +endif() diff --git a/simgear/misc/integer_sequence.hxx b/simgear/std/integer_sequence.hxx similarity index 93% rename from simgear/misc/integer_sequence.hxx rename to simgear/std/integer_sequence.hxx index 47f63c43..8272dd43 100644 --- a/simgear/misc/integer_sequence.hxx +++ b/simgear/std/integer_sequence.hxx @@ -17,13 +17,13 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -#ifndef SIMGEAR_MISC_INTEGER_SEQUENCE_HXX_ -#define SIMGEAR_MISC_INTEGER_SEQUENCE_HXX_ +#ifndef SIMGEAR_STD_INTEGER_SEQUENCE_HXX_ +#define SIMGEAR_STD_INTEGER_SEQUENCE_HXX_ #include +#include "type_traits.hxx" #include -#include #ifndef HAVE_STD_INDEX_SEQUENCE # include @@ -85,4 +85,4 @@ namespace std } #endif -#endif /* SIMGEAR_MISC_INTEGER_SEQUENCE_HXX_ */ +#endif /* SIMGEAR_STD_INTEGER_SEQUENCE_HXX_ */ diff --git a/simgear/misc/integer_sequence_test.cxx b/simgear/std/integer_sequence_test.cxx similarity index 97% rename from simgear/misc/integer_sequence_test.cxx rename to simgear/std/integer_sequence_test.cxx index 74ccd3c2..9447fdb8 100644 --- a/simgear/misc/integer_sequence_test.cxx +++ b/simgear/std/integer_sequence_test.cxx @@ -1,5 +1,4 @@ -#include "integer_sequence.hxx" - +#include #include template diff --git a/simgear/std/type_traits.hxx b/simgear/std/type_traits.hxx new file mode 100644 index 00000000..8146bada --- /dev/null +++ b/simgear/std/type_traits.hxx @@ -0,0 +1,67 @@ +///@file +/// Type Traits (Provide features of later C++ standards) +// +// Copyright (C) 2017 Thomas Geymayer +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +#ifndef SIMGEAR_STD_TYPE_TRAITS_HXX_ +#define SIMGEAR_STD_TYPE_TRAITS_HXX_ + +#include +#include + +namespace std +{ +#ifndef HAVE_STD_REMOVE_CV_T + template + using remove_cv_t = typename remove_cv::type; + + template + using remove_const_t = typename remove_const::type; + + template + using remove_volatile_t = typename remove_volatile::type; + + template + using remove_reference_t = typename remove_reference::type; + + template< class T > + using remove_pointer_t = typename remove_pointer::type; +#endif + +#ifndef HAVE_STD_REMOVE_CVREF_T + template + struct remove_cvref + { + using type = remove_cv_t>; + }; + + template + using remove_cvref_t = typename remove_cvref::type; +#endif + +#ifndef HAVE_STD_ENABLE_IF_T + template + using enable_if_t = typename enable_if::type; +#endif + +#ifndef HAVE_STD_BOOL_CONSTANT + template + using bool_constant = integral_constant; +#endif +} + +#endif /* SIMGEAR_STD_TYPE_TRAITS_HXX_ */ diff --git a/simgear/std/type_traits_test.cxx b/simgear/std/type_traits_test.cxx new file mode 100644 index 00000000..f27f8f0c --- /dev/null +++ b/simgear/std/type_traits_test.cxx @@ -0,0 +1,24 @@ +#include + +using namespace std; + +template +void assert_same() +{ + static_assert(is_same::value, ""); +} + +int main(int argc, char* argv[]) +{ + assert_same, int>(); + assert_same, int volatile>(); + assert_same, int const>(); + assert_same, int const volatile>(); + assert_same, int const volatile>(); + assert_same, int>(); + + assert_same, double>(); + assert_same, integral_constant>(); + + return 0; +}