On Thursday, 16 February 2017 at 00:08:12 UTC, Walter Bright wrote:
On 2/15/2017 12:31 PM, Jonathan M Davis via Digitalmars-d wrote:
It's one of those features that I was surprised when you couldn't do it.

It was an oversight. We just never thought of it.

What do you think about generalizing this feature to allow introducing template value parameters without default value, i.e.:

// Note: `beg` and `end` have no default value

auto bounded
(auto beg, auto end, auto onErrPolicy = Enforce("Value out of range"), T)
    (T value)
{
    return Bounded!(beg, end, Policy)(value);
}

struct Enforce
{ this(string) { /* */ } }

int tmp;
readf("%s", &x);

enum policy = Enforce("User age must be between 18 and 150");
auto userAge = bounded!(18, 150, policy)(tmp);

"Declaring non-type template arguments with auto" is also coming to C++17: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0127r1.html

BTW, shouldn't we use `enum`, instead of `auto`, since everywhere else `enum` means guaranteed to be computed at compile-time whereas `auto` means the opposite?

Reply via email to