NamedType icon indicating copy to clipboard operation
NamedType copied to clipboard

Add support for accessing the phantom tag parameter

Open gotnone opened this issue 1 year ago • 0 comments

I was looking at the feasibility of using NamedType to create some strong lambdas.

See Strong lambdas: strong typing over generic types

Unfortunately, I don't know the type of the resulting strong lambdas until after they are mixed-in. This mix-in is defined in the .cpp file and is not available in a header file. In order to get around this limitation I would like to use a concept to limit the type of functor that can be passed into a class or function defined in a separate header file.

If I use a specific phantom tag it seems like this should allow me to write a concept that is limited to strong lambdas that use the same phantom tag type.

I think it should be as simple as adding the line using TagType = Parameter; to the NamedType implementation.

I can then write a concept that is restricted to that TagType

template <typename F>
using StrongLambda = fluent::NamedType<F, struct SpecialLambdaTag>

template <typename T>
concept SpecialLambda = std::is_same_v<typename StrongLambda::TagType, SpecialLambdaTag>;

I have an example on godbolt.org

gotnone avatar Dec 10 '24 18:12 gotnone