Andrei's list of barriers to D adoption

Olivier via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 13 00:34:49 PDT 2016


On Tuesday, 7 June 2016 at 08:09:49 UTC, Ethan Watson wrote:
> On Tuesday, 7 June 2016 at 07:57:09 UTC, Walter Bright wrote:
>> C++ still suffers from:
>>
>> http://www.digitalmars.com/articles/b44.html
>>
>> and probably always will.
>
> template< size_t size > void function( char ( &array )[ size ] 
> );
>
> It's horrible syntax (no surprise), and being a templated 
> function means it's recompiled N times... but there's at least 
> something for it now.

There is array_view and string_view that have been proposed (and 
I even think  accepted) for C++17.

But if you want a fat pointer, you can just write one yourself:

template< typename T >
struct FatPtr
{
    template< std::size_t N >
    FatPtr( T (&a)[N] )
       : p (a)
       , n (N)
    { }

    T *p;
    std::size_t n;
};

void function( FatPtr<char> a );

int main( )
{
    char a[128];
    function(a);

    function("foo");
}


More information about the Digitalmars-d mailing list