Skip to content

Commit

Permalink
Drop C++03 support and Boost.Preprocessor usage (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Aug 11, 2023
1 parent 7bde4f3 commit b9815d3
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 322 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Expand Up @@ -17,10 +17,7 @@ target_link_libraries(boost_type_index
Boost::config
Boost::container_hash
Boost::core
Boost::preprocessor
Boost::static_assert
Boost::throw_exception
Boost::type_traits
)

if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
Expand Down
2 changes: 1 addition & 1 deletion examples/inheritance.cpp
Expand Up @@ -22,7 +22,7 @@ struct A {
};
struct B: public A { BOOST_TYPE_INDEX_REGISTER_CLASS };
struct C: public B { BOOST_TYPE_INDEX_REGISTER_CLASS };
struct D: public C { BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS) };
struct D: public C { BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS() };

void print_real_type(const A& a) {
std::cout << boost::typeindex::type_id_runtime(a).pretty_name() << '\n';
Expand Down
10 changes: 5 additions & 5 deletions examples/runtime_cast.cpp
Expand Up @@ -18,27 +18,27 @@
#include <iostream>

struct A {
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS)
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS()
virtual ~A()
{}
};

struct B {
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS)
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS()
virtual ~B()
{}
};

struct C : A {
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((A))
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(A)
};

struct D : B {
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((B))
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(B)
};

struct E : C, D {
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((C)(D))
BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(C, D)
};

int main() {
Expand Down
11 changes: 4 additions & 7 deletions include/boost/type_index.hpp
Expand Up @@ -20,9 +20,6 @@
# pragma once
#endif



#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) || \
defined(BOOST_NO_CXX11_CONSTEXPR) || \
Expand All @@ -36,7 +33,7 @@
defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) || \
defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)

BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.TypeIndex 1.82 and will be removed in Boost.TypeIndex 1.84.")
#error C++03 support is dropped in Boost.TypeIndex 1.84

#endif

Expand Down Expand Up @@ -228,7 +225,7 @@ typedef type_index::type_info_t type_info;
/// \throw Nothing.
/// \return boost::typeindex::type_index with information about the specified type T.
template <class T>
inline type_index type_id() BOOST_NOEXCEPT {
inline type_index type_id() noexcept {
return type_index::type_id<T>();
}

Expand All @@ -248,7 +245,7 @@ inline type_index type_id() BOOST_NOEXCEPT {
/// \throw Nothing.
/// \return boost::typeindex::type_index with information about the specified type T.
template <class T>
inline type_index type_id_with_cvr() BOOST_NOEXCEPT {
inline type_index type_id_with_cvr() noexcept {
return type_index::type_id_with_cvr<T>();
}

Expand All @@ -273,7 +270,7 @@ inline type_index type_id_with_cvr() BOOST_NOEXCEPT {
/// \throw Nothing.
/// \return boost::typeindex::type_index with information about the specified variable.
template <class T>
inline type_index type_id_runtime(const T& runtime_val) BOOST_NOEXCEPT {
inline type_index type_id_runtime(const T& runtime_val) noexcept {
return type_index::type_id_runtime(runtime_val);
}

Expand Down
65 changes: 28 additions & 37 deletions include/boost/type_index/ctti_type_index.hpp
Expand Up @@ -22,10 +22,8 @@
#include <boost/type_index/detail/compile_time_type_info.hpp>

#include <cstring>
#include <type_traits>
#include <boost/container_hash/hash.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/remove_reference.hpp>

#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
Expand Down Expand Up @@ -58,24 +56,17 @@ namespace detail {
/// std::cout << ti.pretty_name();
/// \endcode
class ctti_data {
#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
public:
ctti_data() = delete;
ctti_data(const ctti_data&) = delete;
ctti_data& operator=(const ctti_data&) = delete;
#else
private:
ctti_data();
ctti_data(const ctti_data&);
ctti_data& operator=(const ctti_data&);
#endif
};

} // namespace detail

/// Helper method for getting detail::ctti_data of a template parameter T.
template <class T>
inline const detail::ctti_data& ctti_construct() BOOST_NOEXCEPT {
inline const detail::ctti_data& ctti_construct() noexcept {
// Standard C++11, 5.2.10 Reinterpret cast:
// An object pointer can be explicitly converted to an object pointer of a different type. When a prvalue
// v of type "pointer to T1" is converted to the type "pointer to cv T2", the result is static_cast<cv
Expand Down Expand Up @@ -105,93 +96,93 @@ inline const detail::ctti_data& ctti_construct() BOOST_NOEXCEPT {
class ctti_type_index: public type_index_facade<ctti_type_index, detail::ctti_data> {
const char* data_;

inline std::size_t get_raw_name_length() const BOOST_NOEXCEPT;
inline std::size_t get_raw_name_length() const noexcept;

BOOST_CXX14_CONSTEXPR inline explicit ctti_type_index(const char* data) BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR inline explicit ctti_type_index(const char* data) noexcept
: data_(data)
{}

public:
typedef detail::ctti_data type_info_t;

BOOST_CXX14_CONSTEXPR inline ctti_type_index() BOOST_NOEXCEPT
BOOST_CXX14_CONSTEXPR inline ctti_type_index() noexcept
: data_(boost::detail::ctti<void>::n())
{}

inline ctti_type_index(const type_info_t& data) BOOST_NOEXCEPT
inline ctti_type_index(const type_info_t& data) noexcept
: data_(reinterpret_cast<const char*>(&data))
{}

inline const type_info_t& type_info() const BOOST_NOEXCEPT;
BOOST_CXX14_CONSTEXPR inline const char* raw_name() const BOOST_NOEXCEPT;
BOOST_CXX14_CONSTEXPR inline const char* name() const BOOST_NOEXCEPT;
inline const type_info_t& type_info() const noexcept;
BOOST_CXX14_CONSTEXPR inline const char* raw_name() const noexcept;
BOOST_CXX14_CONSTEXPR inline const char* name() const noexcept;
inline std::string pretty_name() const;
inline std::size_t hash_code() const BOOST_NOEXCEPT;
inline std::size_t hash_code() const noexcept;

BOOST_CXX14_CONSTEXPR inline bool equal(const ctti_type_index& rhs) const BOOST_NOEXCEPT;
BOOST_CXX14_CONSTEXPR inline bool before(const ctti_type_index& rhs) const BOOST_NOEXCEPT;
BOOST_CXX14_CONSTEXPR inline bool equal(const ctti_type_index& rhs) const noexcept;
BOOST_CXX14_CONSTEXPR inline bool before(const ctti_type_index& rhs) const noexcept;

template <class T>
BOOST_CXX14_CONSTEXPR inline static ctti_type_index type_id() BOOST_NOEXCEPT;
BOOST_CXX14_CONSTEXPR inline static ctti_type_index type_id() noexcept;

template <class T>
BOOST_CXX14_CONSTEXPR inline static ctti_type_index type_id_with_cvr() BOOST_NOEXCEPT;
BOOST_CXX14_CONSTEXPR inline static ctti_type_index type_id_with_cvr() noexcept;

template <class T>
inline static ctti_type_index type_id_runtime(const T& variable) BOOST_NOEXCEPT;
inline static ctti_type_index type_id_runtime(const T& variable) noexcept;
};


inline const ctti_type_index::type_info_t& ctti_type_index::type_info() const BOOST_NOEXCEPT {
inline const ctti_type_index::type_info_t& ctti_type_index::type_info() const noexcept {
return *reinterpret_cast<const detail::ctti_data*>(data_);
}


BOOST_CXX14_CONSTEXPR inline bool ctti_type_index::equal(const ctti_type_index& rhs) const BOOST_NOEXCEPT {
BOOST_CXX14_CONSTEXPR inline bool ctti_type_index::equal(const ctti_type_index& rhs) const noexcept {
const char* const left = raw_name();
const char* const right = rhs.raw_name();
return /*left == right ||*/ !boost::typeindex::detail::constexpr_strcmp(left, right);
}

BOOST_CXX14_CONSTEXPR inline bool ctti_type_index::before(const ctti_type_index& rhs) const BOOST_NOEXCEPT {
BOOST_CXX14_CONSTEXPR inline bool ctti_type_index::before(const ctti_type_index& rhs) const noexcept {
const char* const left = raw_name();
const char* const right = rhs.raw_name();
return /*left != right &&*/ boost::typeindex::detail::constexpr_strcmp(left, right) < 0;
}


template <class T>
BOOST_CXX14_CONSTEXPR inline ctti_type_index ctti_type_index::type_id() BOOST_NOEXCEPT {
typedef BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type no_ref_t;
typedef BOOST_DEDUCED_TYPENAME boost::remove_cv<no_ref_t>::type no_cvr_t;
BOOST_CXX14_CONSTEXPR inline ctti_type_index ctti_type_index::type_id() noexcept {
typedef typename std::remove_reference<T>::type no_ref_t;
typedef typename std::remove_cv<no_ref_t>::type no_cvr_t;
return ctti_type_index(boost::detail::ctti<no_cvr_t>::n());
}



template <class T>
BOOST_CXX14_CONSTEXPR inline ctti_type_index ctti_type_index::type_id_with_cvr() BOOST_NOEXCEPT {
BOOST_CXX14_CONSTEXPR inline ctti_type_index ctti_type_index::type_id_with_cvr() noexcept {
return ctti_type_index(boost::detail::ctti<T>::n());
}


template <class T>
inline ctti_type_index ctti_type_index::type_id_runtime(const T& variable) BOOST_NOEXCEPT {
inline ctti_type_index ctti_type_index::type_id_runtime(const T& variable) noexcept {
return variable.boost_type_index_type_id_runtime_();
}


BOOST_CXX14_CONSTEXPR inline const char* ctti_type_index::raw_name() const BOOST_NOEXCEPT {
BOOST_CXX14_CONSTEXPR inline const char* ctti_type_index::raw_name() const noexcept {
return data_;
}


BOOST_CXX14_CONSTEXPR inline const char* ctti_type_index::name() const BOOST_NOEXCEPT {
BOOST_CXX14_CONSTEXPR inline const char* ctti_type_index::name() const noexcept {
return data_;
}

inline std::size_t ctti_type_index::get_raw_name_length() const BOOST_NOEXCEPT {
return std::strlen(raw_name() + detail::ctti_skip_size_at_end);
inline std::size_t ctti_type_index::get_raw_name_length() const noexcept {
return std::strlen(raw_name() + detail::skip().size_at_end);
}


Expand All @@ -202,7 +193,7 @@ inline std::string ctti_type_index::pretty_name() const {
}


inline std::size_t ctti_type_index::hash_code() const BOOST_NOEXCEPT {
inline std::size_t ctti_type_index::hash_code() const noexcept {
return boost::hash_range(raw_name(), raw_name() + get_raw_name_length());
}

Expand Down

0 comments on commit b9815d3

Please sign in to comment.