Boost logo

Boost :

Subject: Re: [boost] a (useful?) crtp trick
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2012-08-27 04:28:16

On 24.08.2012 19:50, pavel wrote:
> hi all
> i post this in the hope someone finds this technique useful
> to make long story short, here is a snippet:
> template<typename t> //tag deducing util
> struct base_tag
> {
> typedef decltype(get_tag((t*)42)) type;
> };
> template<typename type,
> typename tag = typename base_tag<type>::type>
> struct Base //crtp base class
> {
> friend tag get_tag(type*); //helper declaration, never defined
> };
> template<typename type> //no mention of tag
> void f(const Base<type>&) //tag is deduced automatically
> {}
I think this only happens to work by accident, because compilers tend to
defer instantiation of function templates until the end of the
translation unit, when a proper instantiation of Base is available. But
without a compiler that doesn't I don't think I can come up with code
that shows this.

In any case, this makes *my* head hurt, and that's saying something.


Boost list run by bdawes at, gregod at, cpdaniel at, john at