强制Boost TypeIndex报告特定的名称
我想指定Boost TypeIndex强制Boost TypeIndex报告特定的名称,boost,typeid,Boost,Typeid,我想指定Boost TypeIndexBoost::TypeIndex::type\u id().pretty\u name()报告的特定类型将产生一个特定的名称 我想解决的问题是,正如在其他地方所报告的那样,有一种特殊情况令人困惑,那就是std::string类型(或别名)被报告为std::\uuuucx11::basic\u string (我理解其原因,std::string是一个别名。我只想在这种特殊情况下覆盖报告的字符串。) 我按照此处的说明操作,自定义代码的开头如下所示: names
Boost::TypeIndex::type\u id().pretty\u name()
报告的特定类型将产生一个特定的名称
我想解决的问题是,正如在其他地方所报告的那样,有一种特殊情况令人困惑,那就是std::string
类型(或别名)被报告为std::\uuuucx11::basic\u string
(我理解其原因,std::string
是一个别名。我只想在这种特殊情况下覆盖报告的字符串。)
我按照此处的说明操作,自定义代码的开头如下所示:
namespace my_namespace { namespace detail {
template <class T> struct typenum;
template <> struct typenum<void>{ enum {value = 0}; };
template <> struct typenum<std::string>{ enum {value = 1}; };
struct my_typeinfo {const char* const type_;};
const my_typeinfo infos[2] = {
{"void"}, {"std::string"}
};
...
...
名称空间我的名称空间{名称空间详细信息{
模板结构typenum;
模板结构typenum{enum{value=0};};
模板结构typenum{enum{value=1};};
结构my_typeinfo{const char*const type_u2;;};
const my_typeinfo infos[2]={
{“void”},{“std::string”}
};
...
...
但最后,我所能做的就是用另一种类型的报告代替一种类型的报告,而不是仅仅修改一个案例
一个轻量级的解决方案可以是专门化boost::typeindex::stl_type_index
(type_id()
)的输出类型,但到那时类的实际静态信息就会丢失。(没有要专门化的类。)
但是如果没有typeid
的完全专门化,这是不可能做到的,这似乎很难做到
有解决方法吗?我更喜欢Boost.Typeindex中的解决方案,而不是运行时字符串替换。这是我发现的一种非常肮脏的方法,但它并不完美,可能会在今后产生其他问题
struct std_string{}; // dummy replacement class name
namespace boost{
namespace typeindex{
template<> boost::typeindex::stl_type_index type_id<std::string>() noexcept{
return type_id<std_string>(); // will report "std_string", ugly, but better than `std::__cxx11::basic_string<...>`
}
}}
struct std_string{};//伪替换类名
名称空间提升{
名称空间类型索引{
模板boost::typeindex::stl_type_index type_id()noexcept{
返回类型_id();//将报告“std_string”,虽然难看,但比'std::u cxx11::basic_string'更好`
}
}}