From 97346351f8acb59fdd7ba23afbd0611bb46eea2a Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 23 Dec 2025 20:23:47 +0300 Subject: [PATCH] Modernize the code (#19) --- .github/workflows/ci.yml | 7 ------ doc/Jamfile.v2 | 2 +- examples/user_defined_typeinfo.hpp | 24 +++++++++---------- include/boost/type_index.hpp | 8 +++---- include/boost/type_index/ctti_type_index.hpp | 6 ++--- .../detail/compile_time_type_info.hpp | 14 +++++------ .../type_index/runtime_cast/pointer_cast.hpp | 4 ++-- .../runtime_cast/reference_cast.hpp | 4 ++-- include/boost/type_index/stl_type_index.hpp | 14 +++++------ .../boost/type_index/type_index_facade.hpp | 4 ++-- test/cmake_subdir_test/CMakeLists.txt | 1 - test/compare_ctti_stl.cpp | 4 ++-- test/ctti_print_name.cpp | 2 +- 13 files changed, 43 insertions(+), 51 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b81cf2b..2f24407 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,13 +41,6 @@ jobs: linkflags: "linkflags=--coverage -lasan -lubsan" gcov_tool: "gcov-10" launcher: "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6" - - toolset: gcc-9 - cxxstd: "03,11,14,17,2a" - os: ubuntu-22.04 - cxxflags: "cxxflags=--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined" - linkflags: "linkflags=--coverage -lasan -lubsan" - gcov_tool: "gcov-9" - launcher: "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.5" - toolset: clang compiler: clang++-14 cxxstd: "03,11,14,17,2a" diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 01157c0..bb00453 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -31,7 +31,7 @@ boostbook standalone : type_index : - boost.root=http://www.boost.org/doc/libs/1_53_0 + boost.root=http://www.boost.org/doc/libs/1_90_0 # boost.root=../../../.. pdf:boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html ; diff --git a/examples/user_defined_typeinfo.hpp b/examples/user_defined_typeinfo.hpp index f8f816a..238b56e 100644 --- a/examples/user_defined_typeinfo.hpp +++ b/examples/user_defined_typeinfo.hpp @@ -23,8 +23,8 @@ namespace my_namespace { class my_class; struct my_struct; -typedef std::vector my_classes; -typedef std::string my_string; +using my_classes = std::vector; +using my_string = std::string; } // namespace my_namespace @@ -96,21 +96,21 @@ class my_type_index: public boost::typeindex::type_index_facade()) {} - inline my_type_index(const type_info_t& data) BOOST_NOEXCEPT + inline my_type_index(const type_info_t& data) noexcept : data_(&data) {} - inline const type_info_t& type_info() const BOOST_NOEXCEPT { + inline const type_info_t& type_info() const noexcept { return *data_; } - inline const char* raw_name() const BOOST_NOEXCEPT { + inline const char* raw_name() const noexcept { return data_->type_; } @@ -119,17 +119,17 @@ public: } template - inline static my_type_index type_id() BOOST_NOEXCEPT { + inline static my_type_index type_id() noexcept { return detail::my_typeinfo_construct(); } template - inline static my_type_index type_id_with_cvr() BOOST_NOEXCEPT { + inline static my_type_index type_id_with_cvr() noexcept { return detail::my_typeinfo_construct(); } template - inline static my_type_index type_id_runtime(const T& variable) BOOST_NOEXCEPT; + inline static my_type_index type_id_runtime(const T& variable) noexcept; }; } // namespace my_namespace @@ -168,7 +168,7 @@ namespace my_namespace { namespace detail { */ namespace my_namespace { template - my_type_index my_type_index::type_id_runtime(const T& variable) BOOST_NOEXCEPT { + my_type_index my_type_index::type_id_runtime(const T& variable) noexcept { // Classes that were marked with `MY_TYPEINDEX_REGISTER_CLASS` will have a // `type_id_runtime()` method. return variable.type_id_runtime(); @@ -204,7 +204,7 @@ struct my_struct: public my_class { */ #define BOOST_TYPE_INDEX_REGISTER_CLASS MY_TYPEINDEX_REGISTER_CLASS namespace boost { namespace typeindex { - typedef my_namespace::my_type_index type_index; + using type_index = my_namespace::my_type_index; }} //] [/type_index_my_type_index_worldwide_typedefs] diff --git a/include/boost/type_index.hpp b/include/boost/type_index.hpp index f51854a..99f38b2 100644 --- a/include/boost/type_index.hpp +++ b/include/boost/type_index.hpp @@ -129,13 +129,13 @@ BOOST_TYPE_INDEX_BEGIN_MODULE_EXPORT /// user defined type_index class. /// /// \b See boost::typeindex::type_index_facade for a full description of type_index functions. - typedef platform_specific type_index; + using type_index = platform_specific; #elif defined(BOOST_TYPE_INDEX_USER_TYPEINDEX) // Nothing to do #elif (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC) - typedef boost::typeindex::stl_type_index type_index; + using type_index = boost::typeindex::stl_type_index; #else - typedef boost::typeindex::ctti_type_index type_index; + using type_index = boost::typeindex::ctti_type_index; #endif /// Depending on a compiler flags, optimal implementation of type_info will be used @@ -145,7 +145,7 @@ BOOST_TYPE_INDEX_BEGIN_MODULE_EXPORT /// some user defined class. /// /// type_info \b is \b not copyable or default constructible. It is \b not assignable too! -typedef type_index::type_info_t type_info; +using type_info = type_index::type_info_t; #if defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED) diff --git a/include/boost/type_index/ctti_type_index.hpp b/include/boost/type_index/ctti_type_index.hpp index d680594..da0b007 100644 --- a/include/boost/type_index/ctti_type_index.hpp +++ b/include/boost/type_index/ctti_type_index.hpp @@ -112,7 +112,7 @@ class ctti_type_index: public type_index_facade::n()) @@ -164,8 +164,8 @@ BOOST_CXX14_CONSTEXPR inline bool ctti_type_index::before(const ctti_type_index& template BOOST_CXX14_CONSTEXPR inline ctti_type_index ctti_type_index::type_id() noexcept { - typedef typename std::remove_reference::type no_ref_t; - typedef typename std::remove_cv::type no_cvr_t; + using no_ref_t = typename std::remove_reference::type; + using no_cvr_t = typename std::remove_cv::type; return ctti_type_index(boost::detail::ctti::n()); } diff --git a/include/boost/type_index/detail/compile_time_type_info.hpp b/include/boost/type_index/detail/compile_time_type_info.hpp index 49f2ebe..e00d3f7 100644 --- a/include/boost/type_index/detail/compile_time_type_info.hpp +++ b/include/boost/type_index/detail/compile_time_type_info.hpp @@ -224,25 +224,25 @@ constexpr ctti_skip skip() noexcept { return detail::make_ctti_skip(0, 0, ""); } template struct make_index_sequence_join, index_seq > { - typedef index_seq type; + using type = index_seq; }; template struct make_index_seq_impl { - typedef typename make_index_sequence_join< + using type = typename make_index_sequence_join< typename make_index_seq_impl::type, typename make_index_seq_impl::type - >::type type; + >::type; }; template struct make_index_seq_impl { - typedef index_seq<> type; + using type = index_seq<>; }; template struct make_index_seq_impl { - typedef index_seq type; + using type = index_seq; }; template @@ -315,10 +315,10 @@ struct ctti { >(); static_assert(!boost::typeindex::detail::skip().until_runtime_length, "Skipping for GCC in C++14 mode is unsupported"); - typedef typename boost::typeindex::detail::make_index_seq_impl< + using idx_seq = typename boost::typeindex::detail::make_index_seq_impl< boost::typeindex::detail::skip().size_at_begin, size - sizeof("const *") + 1 - boost::typeindex::detail::skip().size_at_begin - >::type idx_seq; + >::type; return impl(idx_seq()); } #else diff --git a/include/boost/type_index/runtime_cast/pointer_cast.hpp b/include/boost/type_index/runtime_cast/pointer_cast.hpp index f30a6d5..b98d619 100644 --- a/include/boost/type_index/runtime_cast/pointer_cast.hpp +++ b/include/boost/type_index/runtime_cast/pointer_cast.hpp @@ -35,7 +35,7 @@ BOOST_TYPE_INDEX_BEGIN_MODULE_EXPORT /// an address suitably offset from u. If no such conversion exists, returns nullptr. template T runtime_cast(U* u) noexcept { - typedef typename std::remove_pointer::type impl_type; + using impl_type = typename std::remove_pointer::type; return detail::runtime_cast_impl(u, std::is_base_of()); } @@ -46,7 +46,7 @@ T runtime_cast(U* u) noexcept { /// an address suitably offset from u. If no such conversion exists, returns nullptr. template T runtime_cast(U const* u) noexcept { - typedef typename std::remove_pointer::type impl_type; + using impl_type = typename std::remove_pointer::type; return detail::runtime_cast_impl(u, std::is_base_of()); } diff --git a/include/boost/type_index/runtime_cast/reference_cast.hpp b/include/boost/type_index/runtime_cast/reference_cast.hpp index 08f997c..de5eaa9 100644 --- a/include/boost/type_index/runtime_cast/reference_cast.hpp +++ b/include/boost/type_index/runtime_cast/reference_cast.hpp @@ -46,7 +46,7 @@ struct BOOST_SYMBOL_VISIBLE bad_runtime_cast : std::exception /// suitably offset from u. If no such conversion exists, throws boost::typeindex::bad_runtime_cast. template typename std::add_lvalue_reference::type runtime_cast(U& u) { - typedef typename std::remove_reference::type impl_type; + using impl_type = typename std::remove_reference::type; impl_type* value = detail::runtime_cast_impl( std::addressof(u), std::is_base_of()); if(!value) @@ -61,7 +61,7 @@ typename std::add_lvalue_reference::type runtime_cast(U& u) { /// suitably offset from u. If no such conversion exists, throws boost::typeindex::bad_runtime_cast. template typename std::add_lvalue_reference::type runtime_cast(U const& u) { - typedef typename std::remove_reference::type impl_type; + using impl_type = typename std::remove_reference::type; impl_type* value = detail::runtime_cast_impl( std::addressof(u), std::is_base_of()); if(!value) diff --git a/include/boost/type_index/stl_type_index.hpp b/include/boost/type_index/stl_type_index.hpp index 38e53cc..eb04b9e 100644 --- a/include/boost/type_index/stl_type_index.hpp +++ b/include/boost/type_index/stl_type_index.hpp @@ -117,9 +117,9 @@ class stl_type_index { public: #ifdef BOOST_NO_STD_TYPEINFO - typedef type_info type_info_t; + using type_info_t = type_info; #else - typedef std::type_info type_info_t; + using type_info_t = std::type_info; #endif private: @@ -175,7 +175,7 @@ inline const char* stl_type_index::name() const noexcept { inline std::string stl_type_index::pretty_name() const { static const char cvr_saver_name[] = "boost::typeindex::detail::cvr_saver"; - static BOOST_CONSTEXPR_OR_CONST std::string::size_type cvr_saver_name_len = sizeof(cvr_saver_name) - 1; + constexpr std::string::size_type cvr_saver_name_len = sizeof(cvr_saver_name) - 1; // In case of MSVC demangle() is a no-op, and name() already returns demangled name. // In case of GCC and Clang (on non-Windows systems) name() returns mangled name and demangle() undecorates it. @@ -270,8 +270,8 @@ inline bool stl_type_index::before(const stl_type_index& rhs) const noexcept { template inline stl_type_index stl_type_index::type_id() noexcept { - typedef typename std::remove_reference::type no_ref_t; - typedef typename std::remove_cv::type no_cvr_t; + using no_ref_t = typename std::remove_reference::type; + using no_cvr_t = typename std::remove_cv::type; return typeid(no_cvr_t); } @@ -281,11 +281,11 @@ namespace detail { template inline stl_type_index stl_type_index::type_id_with_cvr() noexcept { - typedef typename std::conditional< + using type = typename std::conditional< std::is_reference::value || std::is_const::value || std::is_volatile::value, detail::cvr_saver, T - >::type type; + >::type; return typeid(type); } diff --git a/include/boost/type_index/type_index_facade.hpp b/include/boost/type_index/type_index_facade.hpp index 7e6261e..5e95e24 100644 --- a/include/boost/type_index/type_index_facade.hpp +++ b/include/boost/type_index/type_index_facade.hpp @@ -42,7 +42,7 @@ BOOST_TYPE_INDEX_BEGIN_MODULE_EXPORT /// class stl_type_index: public type_index_facade /// { /// public: -/// typedef std::type_info type_info_t; +/// using type_info_t = std::type_info; /// private: /// const type_info_t* data_; /// @@ -70,7 +70,7 @@ private: } /// @endcond public: - typedef TypeInfo type_info_t; + using type_info_t = TypeInfo; /// \b Override: This function \b may be redefined in Derived class. Overrides \b must not throw. /// \return Name of a type. By default returns Derived::raw_name(). diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index 7171016..0ba8f36 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -14,7 +14,6 @@ foreach(dep IN ITEMS describe mp11 smart_ptr - static_assert throw_exception unordered predef) diff --git a/test/compare_ctti_stl.cpp b/test/compare_ctti_stl.cpp index b8c0c34..5e94939 100644 --- a/test/compare_ctti_stl.cpp +++ b/test/compare_ctti_stl.cpp @@ -31,8 +31,8 @@ struct my_template {}; template void compare() { - typedef boost::typeindex::ctti_type_index ctti; - typedef boost::typeindex::stl_type_index stl; + using ctti = boost::typeindex::ctti_type_index; + using stl = boost::typeindex::stl_type_index; BOOST_TEST_EQ( ctti::type_id().pretty_name(), stl::type_id().pretty_name() diff --git a/test/ctti_print_name.cpp b/test/ctti_print_name.cpp index e184127..19062eb 100644 --- a/test/ctti_print_name.cpp +++ b/test/ctti_print_name.cpp @@ -36,7 +36,7 @@ int main() << ctti_type_index::type_id() << '\n'; - std::cout << "empty:" + std::cout << "empty: " << ctti_type_index::type_id() << '\n'; return 0;