Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the type of boost::hana::tuple_c implementation-defined?

The Boost.Hana documentation for tuple_c states:

Also note that the type of the objects returned by tuple_c and an equivalent call to make<tuple_tag> may differ.

followed by the following snippet:

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>)
);

However, the actual implementation for tuple_c simply has:

#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

and, indeed, the code snippet works just fine without the to_tuple wrapper:

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>)
);

Question: why is the actual type of tuple_c implementation defined? Isn't the to_tuple wrapper superfluous?

like image 264
TemplateRex Avatar asked Dec 22 '25 09:12

TemplateRex


1 Answers

The phrase "implementation defined" does not describe an implementation. It explicitly states that an implementation choice is left undocumented on purpose, for one reason or another. Of course it is implemented somehow. The users should not rely on any particular implementation but use only documented APIs.

Leaving an implementation choice undocumented is a sensible default unless there's a specific reason to document it. This is true even if there's only one obvious choice today, because tomorrow things may change.

like image 112
n. 1.8e9-where's-my-share m. Avatar answered Dec 23 '25 23:12

n. 1.8e9-where's-my-share m.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!