Boost.Hana documentation对于 tuple_c
状态:
Also note that the type of the objects returned by
tuple_c
and an equivalent call tomake<tuple_tag>
may differ.
后跟以下片段:
BOOST_HANA_CONSTANT_CHECK(
hana::to_tuple(hana::tuple_c<int, 0, 1, 2>)
==
hana::make_tuple(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>)
);
然而,actual implementation对于 tuple_c
只是有:
#ifdef BOOST_HANA_DOXYGEN_INVOKED
template <typename T, T ...v>
constexpr implementation_defined tuple_c{};
#else
template <typename T, T ...v>
constexpr hana::tuple<hana::integral_constant<T, v>...> tuple_c{};
#endif
事实上,代码片段在没有 to_tuple
的情况下也能正常工作包装器:
BOOST_HANA_CONSTANT_CHECK(
hana::tuple_c<int, 0, 1, 2>
==
hana::make_tuple(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>)
);
问题:为什么tuple_c
的实际类型是实现定义?不是 to_tuple
包装多余?
最佳答案
短语“实现定义”并未描述实现。它明确指出出于某种原因,有意未记录实现选择。当然,它是以某种方式 实现的。用户不应依赖任何特定的实现,而应仅使用文档化的 API。
不记录实现选择是一个明智的默认设置,除非有特定的理由记录它。即使今天只有一个明显的选择也是如此,因为明天情况可能会改变。
关于c++ - 为什么 boost::hana::tuple_c 的类型是实现定义的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50101953/