Synthesis of the T interface required by the class template

template <typename T> class A { // use the type parameter T in various ways here } 

Is there a way to automatically synthesize the definition of a valid class for T used by pattern A? My expectation is a compiler tool or trick that could generate boiler plate code for a parameter of type T, which I could tailor to my needs.

I know that if I wrote class A, I could give some hints to the "user" using enhancement concept checks, etc. .... But this is an unfamiliar code base where I did not have the luxury of writing class A. So far I build the necessary class of parameters T manually, reading the code for class A and skillful help from the compiler (with its brief messages).

Is there a better way?

+4
source share
1 answer

If you understand correctly, you are looking for a way to automatically generate a concept archetype for a given template class. This is currently not possible, and perhaps it will never be.

The main problem here is that it is very difficult to say anything about the semantics of code A without prior knowledge of T Dave Abrahams wrote a blog post not so long ago, where he showed that you can call a function without restrictions from code that is limited by concepts and the compiler can still correctly perform concept checks.

But what you are asking for is a compiler that synthesizes conceptual checks from the air. I am not a very compiler, but I can’t figure out how to do this with today's tools. Although, of course, it would be very cool if it became possible some day.

+2
source

Source: https://habr.com/ru/post/1402599/


All Articles