Re: c++0x: static_assert & concepts
On 17 Okt., 02:38, Mathias Gaunard <loufo...@gmail.com> wrote:
On 16 oct, 00:38, SG <s.gesem...@gmail.com> wrote:
There is a way to turn an old-style
compile-time predicate (template<..> struct {..};) into a concept via
std::True. But it doesn't work the other way around, does it?
template<typename T>
struct is_foo
{
static const bool value = false;
};
template<Foo T>
struct is_foo<T>
{
static const bool value = true;
};
Right. But you have to define such a struct for every concept because
something like this
template<concept C, typename... T>
struct is_true
{ static const bool value = false; };
template<concept C, typename... T>
requires C<T>
{ static const bool value = true; };
:::
auto it = get_iterator(); // some non-template code
static_assert(is_true<ForwardIterator,decltype(it)>::value);
:::
(passing a concept as template parameter) isn't allowed as far as I
can tell. This doesn't really fit my definition of "easy". I would
have liked to use
I didn't know it was possible to turn a meta-function into a concept.
How is it done?
concept True<bool B> {}; // is part of the
concept_map True<true> {}; // <concepts> header
template<typename T>
requires True<old_style_predicate<T>::value>
void f(const T&);
In this case we don't need to specify a new concept each time. True<>
can be used with all old-style compile-time predicates.
Cheers,
SG
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]