Fixed issues noted by Paul A. Bristow during review

This commit is contained in:
Antony Polukhin
2014-05-04 14:22:25 +04:00
parent 2e11dc75d4
commit a66ffcfa50
5 changed files with 26 additions and 32 deletions

View File

@ -18,8 +18,8 @@ namespace bti = boost::typeind;
template <class T>
void foo(T) {
std::cout << "\n Short name: " << bti::type_id<T>().raw_name();
std::cout << "\n Readable name: " << bti::type_id<T>().pretty_name();
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

@ -18,22 +18,21 @@
#include <iostream>
#include <stdexcept>
#include <cassert>
namespace bti = boost::typeind;
class type_erased_unary_function {
void* function_ptr_;
bti::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_(bti::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_ != bti::type_id_with_cvr<ParamT>()) {
if (exact_param_t_ != boost::typeind::type_id_with_cvr<ParamT>()) {
throw std::runtime_error("Incorrect `ParamT`");
}

View File

@ -14,7 +14,6 @@
#include <boost/type_index.hpp>
#include <iostream>
namespace bti = boost::typeind;
struct A {
BOOST_TYPE_INDEX_REGISTER_CLASS
@ -24,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 << bti::type_id_runtime(a).pretty_name() << '\n';
std::cout << boost::typeind::type_id_runtime(a).pretty_name() << '\n';
}
int main() {

View File

@ -14,25 +14,24 @@
#include <boost/unordered_set.hpp>
#include <boost/functional/hash.hpp>
#include <cassert>
namespace bti = boost::typeind;
int main() {
boost::unordered_set<bti::type_index> types;
boost::unordered_set<boost::typeind::type_index> types;
// Storing some `boost::type_info`s
types.insert(bti::type_id<int>());
types.insert(bti::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(bti::type_id<const int>()).second;
bool is_inserted = types.insert(boost::typeind::type_id<const int>()).second;
assert(!is_inserted);
assert(types.erase(bti::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() == bti::type_id<int>());
assert(*types.begin() == boost::typeind::type_id<int>());
}
//] [/type_index_registry_example]