/* try.cpp - to try out and experiment with new features.... * scons will create the binary bin/try */ // 06/25 - provide a concept to accept _tuple-like_ objects // 06/25 - investigate function type detection of std::bind Binders // 12/24 - investigate problem when perfect-forwarding into a binder // 12/24 - investigate overload resolution on a templated function similar to std::get // 11/24 - how to define a bare object location comparison predicate // 11/23 - prototype for grouping from iterator /** @file try.cpp * Develop a concept to detect _tuple-like_ classes, based on the requirements * of the »tuple protocol«. Using some ideas from [Stackoverflow] as starting point. * [Stackoverflow]: https://stackoverflow.com/q/68443804/444796 */ #include "lib/format-cout.hpp" #include "lib/test/test-helper.hpp" #include "lib/test/diagnostic-output.hpp" #include "lib/meta/tuple-helper.hpp" #include "lib/hetero-data.hpp" #include "lib/util.hpp" #include using std::string; namespace lib { namespace meta { template concept tuple_sized = requires { { std::tuple_size::value } -> std::convertible_to; }; template concept tuple_adl_accessible = requires(TUP tup) { typename std::tuple_element_t; { get(tup) } -> std::convertible_to&>; }; template concept tuple_mem_accessible = requires(TUP tup) { typename std::tuple_element_t; { tup.template get() } -> std::convertible_to&>; }; template concept tuple_accessible = tuple_mem_accessible or tuple_adl_accessible; template class AndAll { template static constexpr bool canAccessAll (std::index_sequence) { return (tuple_accessible and ...); } using IdxSeq = typename ElmTypes::Idx; public: static constexpr bool can_AccessElement = canAccessAll(IdxSeq{}); }; template concept tuple_like = not is_reference_v and tuple_sized> and AndAll>::can_AccessElement; }}//namespace lib::meta template void show() { SHOW_TYPE(X) } template void show() { cout << "Tup!! "<< lib::test::showType() < ([](auto i) { using Elm = std::tuple_element_t; cout <<" "<() <; using Arr = std::array; using Hetero = lib::HeteroData::Chain::ChainExtent::ChainType; SHOW_EXPR((lib::meta::tuple_sized )) SHOW_EXPR((lib::meta::tuple_sized )) SHOW_EXPR((lib::meta::tuple_sized )) SHOW_EXPR((lib::meta::tuple_sized )) SHOW_EXPR((lib::meta::tuple_accessible)) // SHOW_EXPR((lib::meta::tuple_accessible)) SHOW_EXPR((lib::meta::tuple_accessible)) SHOW_EXPR((lib::meta::AndAll::can_AccessElement)) SHOW_EXPR((lib::meta::AndAll::can_AccessElement)) SHOW_EXPR((lib::meta::tuple_like )) SHOW_EXPR((lib::meta::tuple_like )) SHOW_EXPR((lib::meta::tuple_like )) SHOW_EXPR((lib::meta::tuple_like )) show(); show(); show(); show(); cout << "\n.gulp." <