diff --git a/examples/demangled_names.cpp b/examples/demangled_names.cpp index 2c4d4b7..3460ba8 100644 --- a/examples/demangled_names.cpp +++ b/examples/demangled_names.cpp @@ -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 +#include #include template void foo(T) { - std::cout << "\n Short name: " << boost::type_id().name(); - std::cout << "\n Readable name: " << boost::type_id().name_demangled(); + std::cout << "\n Short name: " << boost::typeind::type_id().raw_name(); + std::cout << "\n Readable name: " << boost::typeind::type_id().pretty_name(); } struct user_defined_type{}; diff --git a/examples/exact_types_match.cpp b/examples/exact_types_match.cpp index e639775..f3e856f 100644 --- a/examples/exact_types_match.cpp +++ b/examples/exact_types_match.cpp @@ -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 +#include #include #include #include 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 type_erased_unary_function(void(*ptr)(ParamT)) : function_ptr_(reinterpret_cast(ptr)) // ptr - is a pointer to function returning `void` and accepting parameter of type `ParamT` - , exact_param_t_(boost::type_id_with_cvr()) + , exact_param_t_(boost::typeind::type_id_with_cvr()) {} template void call(ParamT v) { - if (exact_param_t_ != boost::type_id_with_cvr()) { + if (exact_param_t_ != boost::typeind::type_id_with_cvr()) { throw std::runtime_error("Incorrect `ParamT`"); } diff --git a/examples/inheritance.cpp b/examples/inheritance.cpp index 5cd1cb5..342e2ab 100644 --- a/examples/inheritance.cpp +++ b/examples/inheritance.cpp @@ -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 +#include #include 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() { diff --git a/examples/registry.cpp b/examples/registry.cpp index 16f247c..457cce9 100644 --- a/examples/registry.cpp +++ b/examples/registry.cpp @@ -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 +#include #include +#include #include int main() { - boost::unordered_set types; + boost::unordered_set types; // Storing some `boost::type_info`s - types.insert(boost::type_id()); - types.insert(boost::type_id()); + types.insert(boost::typeind::type_id()); + types.insert(boost::typeind::type_id()); // `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()).second; + bool is_inserted = types.insert(boost::typeind::type_id()).second; assert(!is_inserted); - assert(types.erase(boost::type_id()) == 1); + assert(types.erase(boost::typeind::type_id()) == 1); // We have erased the `float` type, only `int` remains - assert(*types.begin() == boost::type_id()); + assert(*types.begin() == boost::typeind::type_id()); } //] [/type_index_registry_example] diff --git a/include/boost/type_index.hpp b/include/boost/type_index.hpp index 9fc8411..68385a0 100644 --- a/include/boost/type_index.hpp +++ b/include/boost/type_index.hpp @@ -25,6 +25,8 @@ # pragma once #endif +#include + #if (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC) # include #else diff --git a/include/boost/type_index/ctti_type_index.ipp b/include/boost/type_index/ctti_type_index.ipp index 5aa7ee6..56d8b26 100644 --- a/include/boost/type_index/ctti_type_index.ipp +++ b/include/boost/type_index/ctti_type_index.ipp @@ -29,16 +29,9 @@ #include #include -#include #include -#include -#include -#include -#include #include #include -#include -#include #include namespace boost { namespace typeind { namespace detail { @@ -56,7 +49,7 @@ inline const ctti_data& ctti_construct() BOOST_NOEXCEPT { template <> template -type_index_base type_index_base::construct() BOOST_NOEXCEPT { +inline type_index_base type_index_base::construct() BOOST_NOEXCEPT { typedef BOOST_DEDUCED_TYPENAME boost::remove_reference::type no_ref_t; typedef BOOST_DEDUCED_TYPENAME boost::remove_cv::type no_cvr_t; return ctti_construct(); @@ -65,14 +58,14 @@ type_index_base type_index_base::construct() BOOST_NOEXCEP template <> template -type_index_base type_index_base::construct_with_cvr() BOOST_NOEXCEPT { +inline type_index_base type_index_base::construct_with_cvr() BOOST_NOEXCEPT { return ctti_construct(); } template <> template -type_index_base type_index_base::construct_runtime(T& rtti_val) BOOST_NOEXCEPT { +inline type_index_base type_index_base::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 type_index_base::construct_runtime(T& rtti template <> template -type_index_base type_index_base::construct_runtime(T* rtti_val) { +inline type_index_base type_index_base::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 type_index_base::construct_runtime(T* rtti template <> -const char* type_index_base::raw_name() const BOOST_NOEXCEPT { +inline const char* type_index_base::raw_name() const BOOST_NOEXCEPT { return data_->typename_; } template <> -const char* type_index_base::name() const BOOST_NOEXCEPT { +inline const char* type_index_base::name() const BOOST_NOEXCEPT { return data_->typename_; } template <> -std::string type_index_base::pretty_name() const { +inline std::string type_index_base::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::pretty_name() const { template <> -bool type_index_base::equal(const type_index_base& rhs) const BOOST_NOEXCEPT { +inline bool type_index_base::equal(const type_index_base& rhs) const BOOST_NOEXCEPT { return raw_name() == rhs.raw_name() || !std::strcmp(raw_name(), rhs.raw_name()); } template <> -bool type_index_base::before(const type_index_base& rhs) const BOOST_NOEXCEPT { +inline bool type_index_base::before(const type_index_base& 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::hash_code() const BOOST_NOEXCEPT { +inline std::size_t type_index_base::hash_code() const BOOST_NOEXCEPT { return boost::hash_range(raw_name(), raw_name() + std::strlen(raw_name() + detail::ctti_skip_size_at_end)); } diff --git a/include/boost/type_index/stl_type_index.ipp b/include/boost/type_index/stl_type_index.ipp index 1ad7bca..9ab5842 100644 --- a/include/boost/type_index/stl_type_index.ipp +++ b/include/boost/type_index/stl_type_index.ipp @@ -59,7 +59,7 @@ namespace boost { namespace typeind { namespace detail { template <> template -type_index_base type_index_base::construct() BOOST_NOEXCEPT { +inline type_index_base type_index_base::construct() BOOST_NOEXCEPT { typedef BOOST_DEDUCED_TYPENAME boost::remove_reference::type no_ref_t; typedef BOOST_DEDUCED_TYPENAME boost::remove_cv::type no_cvr_t; @@ -75,7 +75,7 @@ type_index_base type_index_base::construct() BOO template <> template -type_index_base type_index_base::construct_with_cvr() BOOST_NOEXCEPT { +inline type_index_base type_index_base::construct_with_cvr() BOOST_NOEXCEPT { typedef typename boost::mpl::if_c< boost::is_reference::value || boost::is_const::value @@ -90,7 +90,7 @@ type_index_base type_index_base::construct_with_ template <> template -type_index_base type_index_base::construct_runtime(T& rtti_val) BOOST_NOEXCEPT { +inline type_index_base type_index_base::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 type_index_base::construct_runti template <> template -type_index_base type_index_base::construct_runtime(T* rtti_val) { +inline type_index_base type_index_base::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 type_index_base::construct_runti template <> -const char* type_index_base::raw_name() const BOOST_NOEXCEPT { +inline const char* type_index_base::raw_name() const BOOST_NOEXCEPT { #ifdef _MSC_VER return data_->raw_name(); #else @@ -122,12 +122,12 @@ const char* type_index_base::raw_name() const BOOST_NOEXCEPT { template <> -const char* type_index_base::name() const BOOST_NOEXCEPT { +inline const char* type_index_base::name() const BOOST_NOEXCEPT { return data_->name(); } template <> -std::string type_index_base::pretty_name() const { +inline std::string type_index_base::pretty_name() const { #if defined(_MSC_VER) std::string ret = data_->name(); #else @@ -182,7 +182,7 @@ std::string type_index_base::pretty_name() const { template <> -bool type_index_base::equal(const type_index_base& rhs) const BOOST_NOEXCEPT { +inline bool type_index_base::equal(const type_index_base& 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::equal(const type_index_base -bool type_index_base::before(const type_index_base& rhs) const BOOST_NOEXCEPT { +inline bool type_index_base::before(const type_index_base& 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::before(const type_index_base -std::size_t type_index_base::hash_code() const BOOST_NOEXCEPT { +inline std::size_t type_index_base::hash_code() const BOOST_NOEXCEPT { #if _MSC_VER > 1600 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5 && defined(__GXX_EXPERIMENTAL_CXX0X__)) return data_->hash_code(); #else diff --git a/include/boost/type_index/type_index_base.hpp b/include/boost/type_index/type_index_base.hpp index 6cc0800..ed49f11 100644 --- a/include/boost/type_index/type_index_base.hpp +++ b/include/boost/type_index/type_index_base.hpp @@ -182,6 +182,10 @@ inline std::basic_ostream& operator<<( #endif // BOOST_NO_TEMPLATED_IOSTREAMS #endif // BOOST_NO_IOSTREAM +template +inline std::size_t hash_value(const type_index_base& lhs) BOOST_NOEXCEPT { + return lhs.hash_code(); +} }}} // namespace boost::typeind::detail diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 118277c..937b1b4 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 = gcc:-fno-rtti clang:-fno-rtti shared off ; -#lib test_lib_nortti : test_lib_nortti-obj : shared off ; +obj test_lib_nortti-obj : test_lib.cpp : shared off ; +lib test_lib_nortti : test_lib_nortti-obj : shared off ; obj test_lib_rtti-obj : test_lib.cpp : shared ; lib test_lib_rtti : test_lib_rtti-obj : shared ; @@ -37,7 +37,7 @@ test-suite type_index [ run type_index_test.cpp $(tlib) ] [ run type_index_test.cpp $(tlib) : : : off : type_index_test_no_rtti ] [ run testing_crossmodule.cpp test_lib_rtti $(tlib) ] -# [ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : off : testing_crossmodule_no_rtti ] + [ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : 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 : : : off : registry_no_rtti ] -# [ run ../examples/exact_types_match.cpp : : : off : exact_types_match_no_rtti ] -# [ run ../examples/demangled_names.cpp : : : off : demangled_names_no_rtti ] -# [ compile-fail ../examples/inheritance.cpp : off : failing_inheritance_example ] + # Examples that must work even with RTTI disabled + [ run ../examples/registry.cpp : : : off : registry_no_rtti ] + [ run ../examples/exact_types_match.cpp : : : off : exact_types_match_no_rtti ] + [ run ../examples/demangled_names.cpp : : : off : demangled_names_no_rtti ] + [ compile-fail ../examples/inheritance.cpp : 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) ] ; +} diff --git a/test/test_lib.cpp b/test/test_lib.cpp index 307298b..8a63284 100644 --- a/test/test_lib.cpp +++ b/test/test_lib.cpp @@ -1,8 +1,6 @@ #define TEST_LIB_SOURCE #include "test_lib.hpp" -#include - namespace user_defined_namespace { class user_defined{}; }