小编Neo*_*Liu的帖子

有没有一种方法测试类型在编译时有"bool operator ==(const type&,const type&)"?

我编写了一个类来测试"type == type"但是当类型没有operator ==时失败了;

template <typename _Type>
double _test(...){
    return 0;
}

template <typename _Type>
auto _test(_Type&& t)->decltype(t == t){
    return 0;
}

template <typename _Type>
struct has_equal_to
{
    static const bool value = sizeof(_test(std::declval<_Type>())) == sizeof(char);
};

struct test{};

int main()
{
    std::cout << has_equal_to<test>::value << std::endl; // compile failed ~~~~
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?或者写一个这样的课是不可能的.....

c++

2
推荐指数
1
解决办法
136
查看次数

如何将 Flatbuffer 数据文件转换为 json?

我使用 flatbuffer 将数据编码为名为“person.txt”的文件,如何将其转换为 json 文件?

我尝试 'flatc --json person.txt person.json' 但它失败了。

我有“person.fbs,person.txt”,怎么做?

flatbuffers

1
推荐指数
1
解决办法
2667
查看次数

标签 统计

c++ ×1

flatbuffers ×1