Boost logo

Boost :

From: Gero Peterhoff (g.peterhoff_at_[hidden])
Date: 2020-09-12 18:33:36


Hi Peter,
i implemented signature_of similar to the function_traits. This is more flexible, but requires C++20.

#include <iostream>
#include <cstdlib>
#include <utility>
#include <boost/type_traits/signature_of.hpp>

int foo(bool, float&, const uint64_t, const double&);

template <typename Type> void show_type() noexcept
{
        std::cout << typeid(Type).name() << std::endl;
}
template <typename Tuple> void show_tuple_types() noexcept
{
        auto show_elems = []<std::size_t... Idx>(const std::index_sequence<Idx...>&) noexcept
        {
                (show_type<std::tuple_element_t<Idx, Tuple>>(), ...);
        };

        show_elems(std::make_index_sequence<std::tuple_size_v<Tuple>>{});
}

int main(const int argc, const char** args)
{
        using sig_foo = boost::signature_of<foo>; // or &foo
        std::cout << "foo\n";
        std::cout << "result:\t\t\t" << typeid(sig_foo::result_type).name() << std::endl;
        std::cout << "tuple<arguments>:\t" << typeid(sig_foo::argument_type).name() << std::endl;
        std::cout << "argument size:\t\t" << boost::argument_size_v<foo> << std::endl;
        std::cout << "argument types are:\n";
        show_tuple_types<typename sig_foo::argument_type>();

        using sig_baz = boost::signature_of<&bar::baz>;
        std::cout << "\nbaz\n";
        std::cout << "result:\t\t\t" << typeid(sig_baz::result_type).name() << std::endl;
        std::cout << "tuple<arguments>:\t" << typeid(sig_baz::argument_type).name() << std::endl;
        std::cout << "argument size:\t\t" << boost::argument_size_v<&bar::baz> << std::endl;
        std::cout << "argument types are:\n";
        show_tuple_types<typename sig_baz::argument_type>();

        return EXIT_SUCCESS;
}

(Hint: typeid ignore references)

regards
Gero

Am 12.09.20 um 17:35 schrieb Peter Dimov via Boost:
> Gero Peterhoff wrote:
>> Hello Developers,
>> I would like to retrofit some type-traits in boost, but I have read https://pdimov.github.io/articles/phasing_out_cxx03.html. Now I don't know how to do it best, as the boost-type-traits may be removed.
>
> Boost.TypeTraits is not made obsolete by C++11, so it won't be removed. It contains both non-standard traits and traits that have been added in a later standard (17, 20). F.ex.
>
> https://www.boost.org/doc/libs/1_74_0/libs/type_traits/doc/html/boost_typetraits/reference/conjunction.html
> https://www.boost.org/doc/libs/1_74_0/libs/type_traits/doc/html/boost_typetraits/reference/detected.html
> https://www.boost.org/doc/libs/1_74_0/libs/type_traits/doc/html/boost_typetraits/reference/function_traits.html
> https://www.boost.org/doc/libs/1_74_0/libs/type_traits/doc/html/boost_typetraits/reference/is_bounded_array.html
> https://www.boost.org/doc/libs/1_74_0/libs/type_traits/doc/html/boost_typetraits/reference/is_list_constructible.html
> https://www.boost.org/doc/libs/1_74_0/libs/type_traits/doc/html/boost_typetraits/reference/is_unscoped_enum.html
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost






Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk