C++ guys hate static_if?

TommiT tommitissari at hotmail.com
Tue Mar 12 08:02:24 PDT 2013


On Tuesday, 12 March 2013 at 13:44:35 UTC, Nick Sabalausky wrote:
> On Tue, 12 Mar 2013 12:51:03 +0100
> "TommiT" <tommitissari at hotmail.com> wrote:
>
>> On Tuesday, 12 March 2013 at 02:39:06 UTC, TommiT wrote:
>> > struct S1 implements A2 {
>> >     void foo() { }
>> >     void bar() { }
>> > }
>> 
>> That's not good. Types shouldn't have to explicitly say that 
>> they implement a concept.
>
> I *strongly* disagree. A much as I love ranges (for example), 
> their
> duckiness is the one thing I consider to be a huge mistake.

The problem with having to explicitl specify that a type 
implements a certain concept, is the resulting strong coupling 
between the concept definition and the type. This prevents "happy 
accidents" like the following from happening:

Alice and Bob write libraries without knowing anything about each 
other or each other's code. Alice implements the following in her 
library:

concept IntegerLike {
     ...
}

void foo(IntegerLike N)(N n) { }

Bob implements the following in his library:

struct SafeInt {
     ...
}

Later Bob realizes that Alice has written this cool function foo 
which accepts his type SafeInt as an argument because SafeInt 
just so happens to fulfill the requirements of the IntegerLike 
concept defined in Alice's library.

Although, the majority of concepts should come from the standard 
library.


More information about the Digitalmars-d mailing list