forked from boostorg/type_index
Restored all the tests and examples, fixed some issues
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
// Copyright 2013-2014 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
@ -12,13 +12,13 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <boost/type_index/type_info.hpp>
|
||||
#include <boost/type_index.hpp>
|
||||
#include <iostream>
|
||||
|
||||
template <class T>
|
||||
void foo(T) {
|
||||
std::cout << "\n Short name: " << boost::type_id<T>().name();
|
||||
std::cout << "\n Readable name: " << boost::type_id<T>().name_demangled();
|
||||
std::cout << "\n Short name: " << boost::typeind::type_id<T>().raw_name();
|
||||
std::cout << "\n Readable name: " << boost::typeind::type_id<T>().pretty_name();
|
||||
}
|
||||
|
||||
struct user_defined_type{};
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
// Copyright 2013-2014 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
@ -14,25 +14,25 @@
|
||||
parameter will be checked for exact match with initaily erased type of function.
|
||||
*/
|
||||
|
||||
#include <boost/type_index/type_index.hpp>
|
||||
#include <boost/type_index.hpp>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
class type_erased_unary_function {
|
||||
void* function_ptr_;
|
||||
boost::type_index exact_param_t_;
|
||||
void* function_ptr_;
|
||||
boost::typeind::type_index exact_param_t_;
|
||||
|
||||
public:
|
||||
template <class ParamT>
|
||||
type_erased_unary_function(void(*ptr)(ParamT))
|
||||
: function_ptr_(reinterpret_cast<void*>(ptr)) // ptr - is a pointer to function returning `void` and accepting parameter of type `ParamT`
|
||||
, exact_param_t_(boost::type_id_with_cvr<ParamT>())
|
||||
, exact_param_t_(boost::typeind::type_id_with_cvr<ParamT>())
|
||||
{}
|
||||
|
||||
template <class ParamT>
|
||||
void call(ParamT v) {
|
||||
if (exact_param_t_ != boost::type_id_with_cvr<ParamT>()) {
|
||||
if (exact_param_t_ != boost::typeind::type_id_with_cvr<ParamT>()) {
|
||||
throw std::runtime_error("Incorrect `ParamT`");
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
// Copyright 2013-2014 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
@ -13,7 +13,7 @@
|
||||
"boost::type_id_rtti_only(T&) requires RTTI"
|
||||
*/
|
||||
|
||||
#include <boost/type_index/type_info.hpp>
|
||||
#include <boost/type_index.hpp>
|
||||
#include <iostream>
|
||||
|
||||
struct A { virtual ~A(){} };
|
||||
@ -21,7 +21,7 @@ struct B: public A {};
|
||||
struct C: public B {};
|
||||
|
||||
void print_real_type(const A& a) {
|
||||
std::cout << boost::type_id_rtti_only(a).name_demangled() << '\n';
|
||||
std::cout << boost::typeind::type_id_runtime(a).pretty_name() << '\n';
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2013 Antony Polukhin
|
||||
// Copyright 2013-2014 Antony Polukhin
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See the accompanying file LICENSE_1_0.txt
|
||||
@ -10,27 +10,28 @@
|
||||
Example works with and without RTTI.
|
||||
*/
|
||||
|
||||
#include <boost/type_index/type_index.hpp>
|
||||
#include <boost/type_index.hpp>
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <cassert>
|
||||
|
||||
int main() {
|
||||
boost::unordered_set<boost::type_index> types;
|
||||
boost::unordered_set<boost::typeind::type_index> types;
|
||||
|
||||
// Storing some `boost::type_info`s
|
||||
types.insert(boost::type_id<int>());
|
||||
types.insert(boost::type_id<float>());
|
||||
types.insert(boost::typeind::type_id<int>());
|
||||
types.insert(boost::typeind::type_id<float>());
|
||||
|
||||
// `types` variable contains two `boost::type_index`es:
|
||||
assert(types.size() == 2);
|
||||
|
||||
// Const, volatile and reference will be striped from the type:
|
||||
bool is_inserted = types.insert(boost::type_id<const int>()).second;
|
||||
bool is_inserted = types.insert(boost::typeind::type_id<const int>()).second;
|
||||
assert(!is_inserted);
|
||||
assert(types.erase(boost::type_id<float&>()) == 1);
|
||||
assert(types.erase(boost::typeind::type_id<float&>()) == 1);
|
||||
|
||||
// We have erased the `float` type, only `int` remains
|
||||
assert(*types.begin() == boost::type_id<int>());
|
||||
assert(*types.begin() == boost::typeind::type_id<int>());
|
||||
}
|
||||
|
||||
//] [/type_index_registry_example]
|
||||
|
@ -25,6 +25,8 @@
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC)
|
||||
# include <boost/type_index/stl_type_index.ipp>
|
||||
#else
|
||||
|
@ -29,16 +29,9 @@
|
||||
#include <boost/type_index/detail/compile_time_type_info.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
#include <boost/type_traits/is_volatile.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/detail/no_exceptions_support.hpp>
|
||||
#include <boost/functional/hash_fwd.hpp>
|
||||
|
||||
namespace boost { namespace typeind { namespace detail {
|
||||
@ -56,7 +49,7 @@ inline const ctti_data& ctti_construct() BOOST_NOEXCEPT {
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<ctti_data> type_index_base<ctti_data>::construct() BOOST_NOEXCEPT {
|
||||
inline type_index_base<ctti_data> type_index_base<ctti_data>::construct() 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;
|
||||
return ctti_construct<no_cvr_t>();
|
||||
@ -65,14 +58,14 @@ type_index_base<ctti_data> type_index_base<ctti_data>::construct() BOOST_NOEXCEP
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<ctti_data> type_index_base<ctti_data>::construct_with_cvr() BOOST_NOEXCEPT {
|
||||
inline type_index_base<ctti_data> type_index_base<ctti_data>::construct_with_cvr() BOOST_NOEXCEPT {
|
||||
return ctti_construct<T>();
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<ctti_data> type_index_base<ctti_data>::construct_runtime(T& rtti_val) BOOST_NOEXCEPT {
|
||||
inline type_index_base<ctti_data> type_index_base<ctti_data>::construct_runtime(T& rtti_val) BOOST_NOEXCEPT {
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(T) && false,
|
||||
"type_id_runtime(T&) and type_index::construct_runtime(T&) require RTTI");
|
||||
|
||||
@ -82,7 +75,7 @@ type_index_base<ctti_data> type_index_base<ctti_data>::construct_runtime(T& rtti
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<ctti_data> type_index_base<ctti_data>::construct_runtime(T* rtti_val) {
|
||||
inline type_index_base<ctti_data> type_index_base<ctti_data>::construct_runtime(T* rtti_val) {
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(T) && false,
|
||||
"type_id_runtime(T*) and type_index::construct_runtime(T*) require RTTI");
|
||||
|
||||
@ -91,18 +84,18 @@ type_index_base<ctti_data> type_index_base<ctti_data>::construct_runtime(T* rtti
|
||||
|
||||
|
||||
template <>
|
||||
const char* type_index_base<ctti_data>::raw_name() const BOOST_NOEXCEPT {
|
||||
inline const char* type_index_base<ctti_data>::raw_name() const BOOST_NOEXCEPT {
|
||||
return data_->typename_;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
const char* type_index_base<ctti_data>::name() const BOOST_NOEXCEPT {
|
||||
inline const char* type_index_base<ctti_data>::name() const BOOST_NOEXCEPT {
|
||||
return data_->typename_;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string type_index_base<ctti_data>::pretty_name() const {
|
||||
inline std::string type_index_base<ctti_data>::pretty_name() const {
|
||||
std::size_t len = std::strlen(raw_name() + ctti_skip_size_at_end);
|
||||
while (raw_name()[len - 1] == ' ') --len; // MSVC sometimes adds whitespaces
|
||||
return std::string(raw_name(), len);
|
||||
@ -110,19 +103,19 @@ std::string type_index_base<ctti_data>::pretty_name() const {
|
||||
|
||||
|
||||
template <>
|
||||
bool type_index_base<ctti_data>::equal(const type_index_base<ctti_data>& rhs) const BOOST_NOEXCEPT {
|
||||
inline bool type_index_base<ctti_data>::equal(const type_index_base<ctti_data>& rhs) const BOOST_NOEXCEPT {
|
||||
return raw_name() == rhs.raw_name() || !std::strcmp(raw_name(), rhs.raw_name());
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
bool type_index_base<ctti_data>::before(const type_index_base<ctti_data>& rhs) const BOOST_NOEXCEPT {
|
||||
inline bool type_index_base<ctti_data>::before(const type_index_base<ctti_data>& rhs) const BOOST_NOEXCEPT {
|
||||
return raw_name() != rhs.raw_name() && std::strcmp(raw_name(), rhs.raw_name()) < 0;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
std::size_t type_index_base<ctti_data>::hash_code() const BOOST_NOEXCEPT {
|
||||
inline std::size_t type_index_base<ctti_data>::hash_code() const BOOST_NOEXCEPT {
|
||||
return boost::hash_range(raw_name(), raw_name() + std::strlen(raw_name() + detail::ctti_skip_size_at_end));
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ namespace boost { namespace typeind { namespace detail {
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<std::type_info> type_index_base<std::type_info>::construct() BOOST_NOEXCEPT {
|
||||
inline type_index_base<std::type_info> type_index_base<std::type_info>::construct() 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;
|
||||
|
||||
@ -75,7 +75,7 @@ type_index_base<std::type_info> type_index_base<std::type_info>::construct() BOO
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<std::type_info> type_index_base<std::type_info>::construct_with_cvr() BOOST_NOEXCEPT {
|
||||
inline type_index_base<std::type_info> type_index_base<std::type_info>::construct_with_cvr() BOOST_NOEXCEPT {
|
||||
typedef typename boost::mpl::if_c<
|
||||
boost::is_reference<T>::value
|
||||
|| boost::is_const<T>::value
|
||||
@ -90,7 +90,7 @@ type_index_base<std::type_info> type_index_base<std::type_info>::construct_with_
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<std::type_info> type_index_base<std::type_info>::construct_runtime(T& rtti_val) BOOST_NOEXCEPT {
|
||||
inline type_index_base<std::type_info> type_index_base<std::type_info>::construct_runtime(T& rtti_val) BOOST_NOEXCEPT {
|
||||
#ifdef BOOST_NO_RTTI
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(T) && false,
|
||||
"type_id_runtime(T&) and type_index::construct_runtime(T&) require RTTI");
|
||||
@ -102,7 +102,7 @@ type_index_base<std::type_info> type_index_base<std::type_info>::construct_runti
|
||||
|
||||
template <>
|
||||
template <class T>
|
||||
type_index_base<std::type_info> type_index_base<std::type_info>::construct_runtime(T* rtti_val) {
|
||||
inline type_index_base<std::type_info> type_index_base<std::type_info>::construct_runtime(T* rtti_val) {
|
||||
#ifdef BOOST_NO_RTTI
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(T) && false,
|
||||
"type_id_runtime(T*) and type_index::construct_runtime(T*) require RTTI");
|
||||
@ -112,7 +112,7 @@ type_index_base<std::type_info> type_index_base<std::type_info>::construct_runti
|
||||
|
||||
|
||||
template <>
|
||||
const char* type_index_base<std::type_info>::raw_name() const BOOST_NOEXCEPT {
|
||||
inline const char* type_index_base<std::type_info>::raw_name() const BOOST_NOEXCEPT {
|
||||
#ifdef _MSC_VER
|
||||
return data_->raw_name();
|
||||
#else
|
||||
@ -122,12 +122,12 @@ const char* type_index_base<std::type_info>::raw_name() const BOOST_NOEXCEPT {
|
||||
|
||||
|
||||
template <>
|
||||
const char* type_index_base<std::type_info>::name() const BOOST_NOEXCEPT {
|
||||
inline const char* type_index_base<std::type_info>::name() const BOOST_NOEXCEPT {
|
||||
return data_->name();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string type_index_base<std::type_info>::pretty_name() const {
|
||||
inline std::string type_index_base<std::type_info>::pretty_name() const {
|
||||
#if defined(_MSC_VER)
|
||||
std::string ret = data_->name();
|
||||
#else
|
||||
@ -182,7 +182,7 @@ std::string type_index_base<std::type_info>::pretty_name() const {
|
||||
|
||||
|
||||
template <>
|
||||
bool type_index_base<std::type_info>::equal(const type_index_base<std::type_info>& rhs) const BOOST_NOEXCEPT {
|
||||
inline bool type_index_base<std::type_info>::equal(const type_index_base<std::type_info>& rhs) const BOOST_NOEXCEPT {
|
||||
#ifdef BOOST_CLASSINFO_COMPARE_BY_NAMES
|
||||
return raw_name() == rhs.raw_name() || !std::strcmp(raw_name(), rhs.raw_name());
|
||||
#else
|
||||
@ -192,7 +192,7 @@ bool type_index_base<std::type_info>::equal(const type_index_base<std::type_info
|
||||
|
||||
|
||||
template <>
|
||||
bool type_index_base<std::type_info>::before(const type_index_base<std::type_info>& rhs) const BOOST_NOEXCEPT {
|
||||
inline bool type_index_base<std::type_info>::before(const type_index_base<std::type_info>& rhs) const BOOST_NOEXCEPT {
|
||||
#ifdef BOOST_CLASSINFO_COMPARE_BY_NAMES
|
||||
return raw_name() != rhs.raw_name() && std::strcmp(raw_name(), rhs.raw_name()) < 0;
|
||||
#else
|
||||
@ -207,7 +207,7 @@ bool type_index_base<std::type_info>::before(const type_index_base<std::type_inf
|
||||
|
||||
|
||||
template <>
|
||||
std::size_t type_index_base<std::type_info>::hash_code() const BOOST_NOEXCEPT {
|
||||
inline std::size_t type_index_base<std::type_info>::hash_code() const BOOST_NOEXCEPT {
|
||||
#if _MSC_VER > 1600 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5 && defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
return data_->hash_code();
|
||||
#else
|
||||
|
@ -182,6 +182,10 @@ inline std::basic_ostream<CharT, TriatT>& operator<<(
|
||||
#endif // BOOST_NO_TEMPLATED_IOSTREAMS
|
||||
#endif // BOOST_NO_IOSTREAM
|
||||
|
||||
template <class TypeInfo>
|
||||
inline std::size_t hash_value(const type_index_base<TypeInfo>& lhs) BOOST_NOEXCEPT {
|
||||
return lhs.hash_code();
|
||||
}
|
||||
|
||||
}}} // namespace boost::typeind::detail
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (C) 2012-2013 Antony Polukhin
|
||||
# Copyright (C) 2012-2014 Antony Polukhin
|
||||
#
|
||||
# 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)
|
||||
@ -19,8 +19,8 @@ nortti = <toolset>gcc:<cxxflags>-fno-rtti <toolset>clang:<cxxflags>-fno-rtti <to
|
||||
|
||||
|
||||
# Making libraries that CANNOT work between rtti-on/rtti-off modules
|
||||
#obj test_lib_nortti-obj : test_lib.cpp : <link>shared <rtti>off ;
|
||||
#lib test_lib_nortti : test_lib_nortti-obj : <link>shared <rtti>off ;
|
||||
obj test_lib_nortti-obj : test_lib.cpp : <link>shared <rtti>off ;
|
||||
lib test_lib_nortti : test_lib_nortti-obj : <link>shared <rtti>off ;
|
||||
|
||||
obj test_lib_rtti-obj : test_lib.cpp : <link>shared ;
|
||||
lib test_lib_rtti : test_lib_rtti-obj : <link>shared ;
|
||||
@ -37,7 +37,7 @@ test-suite type_index
|
||||
[ run type_index_test.cpp $(tlib) ]
|
||||
[ run type_index_test.cpp $(tlib) : : : <rtti>off : type_index_test_no_rtti ]
|
||||
[ run testing_crossmodule.cpp test_lib_rtti $(tlib) ]
|
||||
# [ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : <rtti>off : testing_crossmodule_no_rtti ]
|
||||
[ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : <rtti>off : testing_crossmodule_no_rtti ]
|
||||
|
||||
# Mixing RTTI on and off
|
||||
[ link-fail testing_crossmodule.cpp $(tlib) test_lib_rtti : $(nortti) : link_fail_nortti_rtti ]
|
||||
@ -46,16 +46,16 @@ test-suite type_index
|
||||
[ run testing_crossmodule.cpp $(tlib) test_lib_rtti_compat : : : $(nortti) $(compat) : testing_crossmodule_nortti_rtti_compat ]
|
||||
[ run testing_crossmodule.cpp $(tlib) test_lib_nortti_compat : : : $(compat) : testing_crossmodule_rtti_nortti_compat ]
|
||||
|
||||
# # Examples that must work even with RTTI disabled
|
||||
# [ run ../examples/registry.cpp : : : <rtti>off : registry_no_rtti ]
|
||||
# [ run ../examples/exact_types_match.cpp : : : <rtti>off : exact_types_match_no_rtti ]
|
||||
# [ run ../examples/demangled_names.cpp : : : <rtti>off : demangled_names_no_rtti ]
|
||||
# [ compile-fail ../examples/inheritance.cpp : <rtti>off : failing_inheritance_example ]
|
||||
# Examples that must work even with RTTI disabled
|
||||
[ run ../examples/registry.cpp : : : <rtti>off : registry_no_rtti ]
|
||||
[ run ../examples/exact_types_match.cpp : : : <rtti>off : exact_types_match_no_rtti ]
|
||||
[ run ../examples/demangled_names.cpp : : : <rtti>off : demangled_names_no_rtti ]
|
||||
[ compile-fail ../examples/inheritance.cpp : <rtti>off : failing_inheritance_example ]
|
||||
;
|
||||
|
||||
# Assuring that examples compile and run. Adding sources from `examples` directory to the `type_index` test suite.
|
||||
#for local p in [ glob ../examples/*.cpp ]
|
||||
#{
|
||||
# type_index += [ run $(p) ] ;
|
||||
#}
|
||||
for local p in [ glob ../examples/*.cpp ]
|
||||
{
|
||||
type_index += [ run $(p) ] ;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
#define TEST_LIB_SOURCE
|
||||
#include "test_lib.hpp"
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
namespace user_defined_namespace {
|
||||
class user_defined{};
|
||||
}
|
||||
|
Reference in New Issue
Block a user