|
Boost : |
Subject: Re: [boost] [GSoC] [Boost.Hana] Formal review request
From: Roland Bock (rbock_at_[hidden])
Date: 2014-08-01 07:56:01
On 2014-08-01 13:27, pfultz2 wrote:
>> I am therefore rather sticking with static_assert to enforce constraints
>> with friendly error messages for the time being until Concepts Lite are
>> available as TS or part of the standard.
> Using static_assert to enforce constraints can become problematic when used
> with concept predicates. That is because static_assert causes a hard error.
> So, when its combined with function overloading, I would get a friendly
> error
> message, rather than the compiler calling the alternative function. This can
> be workaround by specializing the trait, which is possible with Tick, but
> not
> with `concept bool`.
Sure. My answer was probably too short. I use enable_if, too, of course,
and I use "partial specialization" of functions via a helper struct, etc.
>
> A lot of these problems will start showing up as more people start using
> concept predicate in C++11 and beyond. The difference between a hard error
> and
> template constraint is not really fully understood or utilized by many
> libraries. So to be prepared for the future you should use enable_if which
> is
> a template constraint, instead of static_assert which just produces an
> error.
> Most modern compilers will produce nice friendly messages for enable_if.
>
I don't agree. There are situations where static assert is just perfect.
Some things just must not happen. If they occur, it is an error. I use
static_assert to catch those. I am using it in sqlpp11 and wouldn't want
to express everything with enable_if instead.
Of course, enable_if also has its place and I use it, but much less than
before.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk