On 27.09.2016 01:34, Stefan Ram wrote:
> "Alf P. Steinbach" <
alf.p.stein...@gmail.com> writes:
>> Not sure exactly what you're quoting here or what you're asking for
>> rationale about, can you clarify?
>
> The rationale for the apparent guideline to write
>
> const int i = 2;
>
> instead of
>
> int const i = 2;
>
> . I was quoting the Library Design Guidelines
> (Standard Library Guidelines) from
isocpp.org.
>
Oh, I understand. Sorry.
Well, standard library work has to follow the conventions already
established for the C++ standard. It would be just too much work to
change those conventions now. So that's a very direct rationale.
I read “the wrong place” as an acknowledgment that the original choice,
back in the 1990's, was sub-optimal.
But, in modern C++ we don't have to cater to the idiosyncracies of the C
declaration syntax.
We can just define a `Ptr_` type builder, and a `Ref_`, and so on.
• • •
At first, years ago, I went all the way and also defined `Const_`.
But it's silly to define a new syntax where the current one works.
I found it useful to define a `With_const_like_`, in order to transfer
constness from one type to another. But I'm still searching for a
better, shorter name for that.
• • •
There is also a more radical idea of defining `const` versions of all
the basic types and require use of e.g. `Var_` to make something
mutable. I don't think this idea can be made practically workable: the
confusion would be akin to redefining `+` as `-`. But with this idea
Ptr_<Int> p;
would not compile, because it would declare an uninitialized `int const*
const`.
One would have write e.g.
Var_<Ptr_<Int_>> p;
to get something mutable.
Or
Ptr_<Var_<Int>> p = &blah;
:)
Cheers!,
- Alf