scnlib icon indicating copy to clipboard operation
scnlib copied to clipboard

Concept / SFINAE for if user-defined type is supported

Open triplejam opened this issue 6 months ago • 1 comments

What is the equivalent of fmt's fmt::is_formattable<T>() for user-defined types? I noticed at the moment it just fails with a static_assert.

triplejam avatar Jul 02 '25 09:07 triplejam

Here's a basic one I wrote. You will probably want to rename it because, looking into the implementation in the library, scannable<T> might mean something else already. Also rewriting it to make it backwards compatible with what older C++ standards are currently supported:

template<typename T>
constexpr bool is_custom_wrapper = false;

template<typename T, typename Context>
constexpr bool is_custom_wrapper<scn::detail::custom_wrapper<T, Context>> =
    true;

template<typename T, typename Char = char>
constexpr bool is_scannable =
    is_custom_wrapper<decltype(scn::detail::arg_mapper<Char>().map(
        std::declval<T&>(), scn::detail::context_tag<scn::basic_scan_context<
                                scn::detail::buffer_range_tag, Char>>{}))>;

template<typename T, typename Char = char>
concept scannable = is_scannable<T>;

triplejam avatar Jul 25 '25 13:07 triplejam