Changed namespace to boost::typeindex

This commit is contained in:
Antony Polukhin
2014-05-04 14:42:12 +04:00
parent a66ffcfa50
commit 5ed8543025
21 changed files with 132 additions and 133 deletions

View File

@ -14,12 +14,11 @@
#include <boost/type_index.hpp>
#include <iostream>
namespace bti = boost::typeind;
template <class T>
void foo(T) {
std::cout << "\n Short name: " << boost::typeind::type_id<T>().raw_name();
std::cout << "\n Readable name: " << boost::typeind::type_id<T>().pretty_name();
std::cout << "\n Short name: " << boost::typeindex::type_id<T>().raw_name();
std::cout << "\n Readable name: " << boost::typeindex::type_id<T>().pretty_name();
}
struct user_defined_type{};

View File

@ -21,18 +21,18 @@
class type_erased_unary_function {
void* function_ptr_;
boost::typeind::type_index exact_param_t_;
boost::typeindex::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::typeind::type_id_with_cvr<ParamT>())
, exact_param_t_(boost::typeindex::type_id_with_cvr<ParamT>())
{}
template <class ParamT>
void call(ParamT v) {
if (exact_param_t_ != boost::typeind::type_id_with_cvr<ParamT>()) {
if (exact_param_t_ != boost::typeindex::type_id_with_cvr<ParamT>()) {
throw std::runtime_error("Incorrect `ParamT`");
}

View File

@ -23,7 +23,7 @@ struct B: public A { BOOST_TYPE_INDEX_REGISTER_CLASS };
struct C: public B { BOOST_TYPE_INDEX_REGISTER_CLASS };
void print_real_type(const A& a) {
std::cout << boost::typeind::type_id_runtime(a).pretty_name() << '\n';
std::cout << boost::typeindex::type_id_runtime(a).pretty_name() << '\n';
}
int main() {

View File

@ -16,22 +16,22 @@
#include <cassert>
int main() {
boost::unordered_set<boost::typeind::type_index> types;
boost::unordered_set<boost::typeindex::type_index> types;
// Storing some `boost::type_info`s
types.insert(boost::typeind::type_id<int>());
types.insert(boost::typeind::type_id<float>());
types.insert(boost::typeindex::type_id<int>());
types.insert(boost::typeindex::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::typeind::type_id<const int>()).second;
bool is_inserted = types.insert(boost::typeindex::type_id<const int>()).second;
assert(!is_inserted);
assert(types.erase(boost::typeind::type_id<float&>()) == 1);
assert(types.erase(boost::typeindex::type_id<float&>()) == 1);
// We have erased the `float` type, only `int` remains
assert(*types.begin() == boost::typeind::type_id<int>());
assert(*types.begin() == boost::typeindex::type_id<int>());
}
//] [/type_index_registry_example]

View File

@ -7,7 +7,7 @@
//[type_index_my_type_index_worldwide_macro
/*`
There is an easy way to force `boost::typeind::type_id` to use your own type_index class.
There is an easy way to force `boost::typeindex::type_id` to use your own type_index class.
All we need to do is just define `BOOST_TYPE_INDEX_USER_TYPEINDEX` to the full path to header file
of your type index class:
@ -56,7 +56,7 @@ int main() {
/*`
That's it! Now all TypeIndex global methods and typedefs will be using your class:
*/
boost::typeind::type_index worldwide = boost::typeind::type_id<my_classes>();
boost::typeindex::type_index worldwide = boost::typeindex::type_id<my_classes>();
assert(worldwide.pretty_name() == "my_classes");
assert(worldwide == my_type_index::type_id<my_classes>());
//][/type_index_my_type_index_worldwide_usage]

View File

@ -75,7 +75,7 @@ namespace my_namespace { namespace detail {
*/
namespace my_namespace {
class my_type_index: public boost::typeind::type_index_facade<my_type_index, detail::my_typeinfo> {
class my_type_index: public boost::typeindex::type_index_facade<my_type_index, detail::my_typeinfo> {
const detail::my_typeinfo* data_;
public:
@ -118,7 +118,7 @@ public:
} // namespace my_namespace
/*`
Note that we have used the boost::typeind::type_index_facade class as base.
Note that we have used the boost::typeindex::type_index_facade class as base.
That class took care about all the helper function and operators (comparison, hashing, ostreaming and others).
*/
@ -186,7 +186,7 @@ struct my_struct: public my_class {
You'll also need to add some typedefs and macro to your "user_defined_typeinfo.hpp" header file:
*/
#define BOOST_TYPE_INDEX_REGISTER_CLASS MY_TYPEINDEX_REGISTER_CLASS
namespace boost { namespace typeind {
namespace boost { namespace typeindex {
typedef my_namespace::my_type_index type_index;
}}
//] [/type_index_my_type_index_worldwide_typedefs]