Restored all the tests and examples, fixed some issues

This commit is contained in:
Antony Polukhin
2014-02-06 18:42:08 +04:00
parent c43f8c1cfa
commit 2f9c4b7834
10 changed files with 61 additions and 63 deletions

View File

@ -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{};

View File

@ -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`");
}

View File

@ -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() {

View File

@ -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]