• Re: "Herb Sutter: Why C++ Is Growing and What C++26 Means for

    From boltar@3:633/10 to All on Thu May 14 08:01:04 2026
    On Wed, 13 May 2026 10:17:32 +0200
    David Brown <david.brown@hesbynett.no> gabbled:
    On 13/05/2026 09:55, boltar@caprica.universe wrote:
    template<typename T1, typename T2>
    X add(T1 a, T2 b)
    {
    return a + b;
    }

    What type should X be? It depends on the types of "a" and "b" (which
    might be class types here). So you can write:

    template<typename T1, typename T2>
    auto add(T1 a, T2 b) -> decltype(a + b)
    {
    return a + b;
    }

    A sane syntax would have been

    template<typename T1, typename T2>
    (T1 + T2) add(T1 a, T2 b)
    {
    :
    }

    But this is C++ so not a chance, lets make it as verbose as possible.

    You might also use it for complicated types, such as returning a
    function pointer, where it is clearer:

    int (*get_function_pointer(int x))(int);

    auto get_func_pointer(int x) -> int(*)(int);

    I'll give you that, but the C function pointer syntax was unnecessarily
    messy and there's no reason C++ couldn't have tidied it up even before std::function came along. Something like:

    int (*(int))get_func_pointer(x)
    {
    :
    }


    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From David Brown@3:633/10 to All on Thu May 14 11:22:47 2026
    On 14/05/2026 10:01, boltar@caprica.universe wrote:
    On Wed, 13 May 2026 10:17:32 +0200
    David Brown <david.brown@hesbynett.no> gabbled:
    On 13/05/2026 09:55, boltar@caprica.universe wrote:
    template<typename T1, typename T2>
    X add(T1 a, T2 b)
    {
    ˙˙˙˙return a + b;
    }

    What type should X be?˙ It depends on the types of "a" and "b" (which
    might be class types here).˙ So you can write:

    template<typename T1, typename T2>
    auto add(T1 a, T2 b) -> decltype(a + b)
    {
    ˙˙˙˙return a + b;
    }

    A sane syntax would have been

    template<typename T1, typename T2>
    (T1 + T2) add(T1 a, T2 b)
    {
    :
    }

    But this is C++ so not a chance, lets make it as verbose as possible.

    You might also use it for complicated types, such as returning a
    function pointer, where it is clearer:

    int (*get_function_pointer(int x))(int);

    auto get_func_pointer(int x) -> int(*)(int);

    I'll give you that, but the C function pointer syntax was unnecessarily
    messy and there's no reason C++ couldn't have tidied it up even before std::function came along. Something like:

    int (*(int))get_func_pointer(x)
    {
    :
    }


    I don't think anyone sees the C or C++ type syntaxes as being the nicest conceivable for a programming language. But the languages are what they
    are, stretching back to a time when the syntax choices were made as good design decisions. Modern C++ cannot start from scratch - new features
    have to fit with the existing language, existing tools, existing
    programmers, and existing code. Sometimes things can be "tidied up" a
    bit - that's exactly the case for trailing return types. (It might have
    been nicer if a new keyword - say, "func" - had been introduced to mean exactly the same as "auto" but only available for function declarations.
    But new keywords are not free in an established language.)



    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From boltar@3:633/10 to All on Thu May 14 15:00:39 2026
    On Thu, 14 May 2026 11:22:47 +0200
    David Brown <david.brown@hesbynett.no> gabbled:
    I don't think anyone sees the C or C++ type syntaxes as being the nicest >conceivable for a programming language. But the languages are what they >are, stretching back to a time when the syntax choices were made as good >design decisions. Modern C++ cannot start from scratch - new features
    have to fit with the existing language, existing tools, existing >programmers, and existing code. Sometimes things can be "tidied up" a
    bit - that's exactly the case for trailing return types. (It might have >been nicer if a new keyword - say, "func" - had been introduced to mean >exactly the same as "auto" but only available for function declarations.
    But new keywords are not free in an established language.)

    True, but sometimes the bullet has to be bitten and they just need to
    be introduced. If they cause backwards compat problems with older software thats just tough luck. Eg new, delete, virtual, try, throw etc were all new keywords that are not in C.


    --- PyGate Linux v1.5.14
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)