Skip to content

I really dislike the angle-brackets in dim<>(some_number) #260

@Som1Lse

Description

@Som1Lse

Would it make sense to make dim a function like the following? (where Dim is the exact same type as the current dim, just renamed)

template <std::ptrdiff_t N>
constexpr Dim<N> dim() noexcept {
    static_assert(N >= 0,"something something less than zero");
    return Dim<N>();
}

template <std::ptrdiff_t N = dynamic_range>
constexpr Dim<N> dim(std::ptrdiff_t n) noexcept {
    static_assert(N == dynamic_range,"something something dynamic_range");
    return Dim<>(n);
}

void f(){
    dim<dynamic_range>(4);//still compiles
    dim<>(4);//still compiles
    dim(4);//now compiles
    dim<4>();//now compiles

    dim<4>(4);//does not compile
    dim();//does not compile
    dim<dynamic_range>();//does not compile
}

Of course Dim does not have to be the name of the type, it is backwards compatible with most user-code. The exception to that is if someone wrote their own as_span-like function which takes dims or for some reason decides to create variables of the type (without auto), which I would expect to be reasonably rare, and easy to mitigate since these uses will almost certainly cause a compiler error, and the solution is a matter of replacing a few symbols with slightly different ones.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions