These are chat archives for boostorg/hana

15th
May 2015
Manu Sánchez
@Manu343726
May 15 2015 21:41

Hi Louis. I managed to get a couple of hours to play with this. Some tips:

  • I have forked pfultz2/Tick C++11 concepts definition lib. My fork just adds a constexpr predicate as gcc-clite expects. Given a tick trait T, I also add a T() predicate in a nested conceptsnamespace. Just a first approximation, I'm not very happy because of naming: Traits are usually snake case, but I find concepts on camel case more readable (Like the proposal). So concepts::is_integral() does not look very well for me. Integral looks better.

  • After playing a bit I finally found a way to successfully do partial template specialization on templates constrained with concepts: Define a concept which represents any type (I named it Auto following proposal wording about the unconstrained type concept)

     template<typename T>
     constexpr bool Auto()
     {
         return true;
     }

    Use it instead of typenamekeyword. In other words, all parameters that will be specialized based on a concept constraint should be constrained at the beginning too. Else build fails with a type/value mismatch. Do the same with template template parameters.

     template<typename T> //Does not work. 
     struct foo
     {
         typedef struct error {} type;
     };
    
     template<Comparable T> //Type/value mismatch here. Use Auto concept instead of typename above
     struct foo<T>
     {
         using type = void;
     };

    The cool point is that this works on all levels. For example, this is how I'm defining the Template concept:

     template<template<Auto...> class T>
     consexpt bool Template()
     {
         return true;
     }
Louis Dionne
@ldionne
May 15 2015 22:55
Wow, that’s cool! I asked Andrew Sutton about it, and he told me templates could be used in concepts. I’m at C++Now right now but I’ll be back home sunday; I’ll take a closer look into this then.