Re: Tabs As Syntax

Liste des GroupesRevenir à ol advocacy 
Sujet : Re: Tabs As Syntax
De : OFeem1987 (at) *nospam* teleworm.us (Chris Ahlstrom)
Groupes : comp.os.linux.advocacy
Date : 24. Mar 2024, 14:43:15
Autres entêtes
Organisation : None
Message-ID : <utp755$c5vq$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : slrn/1.0.3 (Linux)
DFS wrote this copyrighted missive and expects royalties:

On 3/23/2024 8:11 AM, Chris Ahlstrom wrote:
>
te<typename ... Args>
std::string string_format (const std::string & format, Args ... args)
{
     std::string result;
     size_t sz = std::snprintf(nullptr, 0, format.c_str(), args ...);
     if (sz > 0)
     {
         std::unique_ptr<char []> buf(new char[sz + 1]);
         std::snprintf(buf.get(), sz + 1, format.c_str(), args ...);
         result = std::string(buf.get(), buf.get() + sz);
     }
     return result;
}
 
Note the variadic template.

Heh, didn't notice that "template" got chopped to "te". Fumble-fingers!

I note the two thousand uses of std::.

Actually, I left out one for the size_t declaration: std::size_t.

Couldn't you just use 'using namespace std;' inside this function (or
whatever this 'te' thing is?)
                  ^ template   DOH!

Like Larry said about using them in headers. But I will use them in headers in
this manner:

namespace foo
{
    using container = std::vector<std::byte>;

    class bar
    {
        using container = std::map<std::string, std::string>;
        . . .
    };
}

So the caller can choose to use foo::container or foo::bar::container.

If all those namespace bug you, you will surely hate the Boost libraries.
As I recall, it has nested namespaces galore.

One other note: I never use "using namespace std", even in the cpp file.
Also the same with namespaces used in other libraries, including my own
libraries. Better to show them upfront to avoid puzzlement.

And I don't do that in main(), either... always specify the namespace.
Adds clarity (and clutter, I will admit).

--
Q: What do Winnie the Pooh and John the Baptist have in common?
A: The same middle name.

Date Sujet#  Auteur
20 Mar 24 * Tabs As Syntax51Nuxxie
20 Mar 24 +* Re: Tabs As Syntax48Chris Ahlstrom
20 Mar 24 i+* Re: Tabs As Syntax32DFS
20 Mar 24 ii+* Re: The more spastic the code, the greater the whitespace & comments.2DFS
20 Mar 24 iii`- Best Practice.1Relf
21 Mar 24 ii+- Re: Tabs As Syntax1Lawrence D'Oliveiro
21 Mar 24 ii`* Re: Tabs As Syntax28rbowman
21 Mar 24 ii +* Re: Tabs As Syntax3Lawrence D'Oliveiro
22 Mar 24 ii i`* Re: Tabs As Syntax2rbowman
22 Mar 24 ii i `- Re: Tabs As Syntax1Lawrence D'Oliveiro
21 Mar 24 ii +* Re: Tabs As Syntax7DFS
22 Mar 24 ii i`* Re: Tabs As Syntax6rbowman
22 Mar 24 ii i +- Re: Tabs As Syntax1Lawrence D'Oliveiro
22 Mar 24 ii i +* Re: Tabs As Syntax3candycanearter07
22 Mar 24 ii i i`* Re: Tabs As Syntax2Chris Ahlstrom
23 Mar 24 ii i i `- Re: Tabs As Syntax1rbowman
22 Mar 24 ii i `- Re: Tabs As Syntax1DFS
21 Mar 24 ii `* Re: Tabs As Syntax17Chris Ahlstrom
22 Mar 24 ii  +* Re: Tabs As Syntax14rbowman
22 Mar 24 ii  i+* Re: Tabs As Syntax11Chris Ahlstrom
22 Mar 24 ii  ii+* Re: Tabs As Syntax2candycanearter07
22 Mar 24 ii  iii`- Re: Tabs As Syntax1Chris Ahlstrom
23 Mar 24 ii  ii`* Re: Tabs As Syntax8Lawrence D'Oliveiro
23 Mar 24 ii  ii `* Re: Tabs As Syntax7Chris Ahlstrom
23 Mar 24 ii  ii  +* Re: Tabs As Syntax5DFS
23 Mar 24 ii  ii  i+- Re: Tabs As Syntax1rbowman
24 Mar 24 ii  ii  i+- Re: Tabs As Syntax1Lawrence D'Oliveiro
24 Mar 24 ii  ii  i`* Re: Tabs As Syntax2Chris Ahlstrom
24 Mar 24 ii  ii  i `- Re: Tabs As Syntax1Physfitfreak
23 Mar 24 ii  ii  `- Re: Tabs As Syntax1rbowman
27 Mar 24 ii  i`* Re: Tabs As Syntax2DFS
28 Mar 24 ii  i `- Re: Tabs As Syntax1rbowman
22 Mar 24 ii  `* Re: Tabs As Syntax2Lawrence D'Oliveiro
22 Mar 24 ii   `- Re: Tabs As Syntax1Chris Ahlstrom
21 Mar 24 i`* Re: Tabs As Syntax15Lawrence D'Oliveiro
26 Mar 24 i `* Re: Tabs As Syntax14DFS
3 Apr 24 i  `* Re: Tabs As Syntax13Lawrence D'Oliveiro
3 Apr 24 i   `* Re: Tabs As Syntax12DFS
5 Apr 24 i    `* Re: Tabs As Syntax11Lawrence D'Oliveiro
5 Apr 24 i     +* Re: Tabs As Syntax6DFS
5 Apr 24 i     i`* Re: Tabs As Syntax5Lawrence D'Oliveiro
5 Apr 24 i     i `* Re: Tabs As Syntax4DFS
6 Apr 24 i     i  `* Re: Tabs As Syntax3Lawrence D'Oliveiro
6 Apr 24 i     i   `* Re: Tabs As Syntax2DFS
6 Apr 24 i     i    `- Re: Tabs As Syntax1Lawrence D'Oliveiro
5 Apr 24 i     `* Re: Tabs As Syntax4Chris Ahlstrom
5 Apr 24 i      `* Re: Tabs As Syntax3candycanearter07
5 Apr 24 i       `* Re: Tabs As Syntax2Chris Ahlstrom
6 Apr 24 i        `- Re: Tabs As Syntax1candycanearter07
20 Mar 24 +- Re: Tabs As Syntax1DFS
21 Mar 24 `- Re: Tabs As Syntax1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal