Deutsch   English   Français   Italiano  
<utp755$c5vq$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Chris Ahlstrom <OFeem1987@teleworm.us>
Newsgroups: comp.os.linux.advocacy
Subject: Re: Tabs As Syntax
Date: Sun, 24 Mar 2024 08:43:15 -0400
Organization: None
Lines: 59
Message-ID: <utp755$c5vq$1@dont-email.me>
References: <17be73f7d87a06e9$246570$4075406$802601b3@news.usenetexpress.com>
 <utejt0$1fq95$1@dont-email.me> <uterkv$1haln$2@dont-email.me>
 <l624u3Fn16lU13@mid.individual.net> <uthf4s$28e7g$1@dont-email.me>
 <l64bi6F2m1hU17@mid.individual.net> <utjt1t$2tns5$1@dont-email.me>
 <utl4m5$3700q$6@dont-email.me> <utmgt6$3k6u5$3@dont-email.me>
 <utmo8b$3m8el$1@dont-email.me>
Reply-To: OFeem1987@teleworm.us
Injection-Date: Sun, 24 Mar 2024 12:43:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aee499f110845a23424a36b92b1eaf78";
	logging-data="399354"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18YixoowZtg+rjvRjA1O7rH"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:lppn5wizHDYAV5xfa4AselvCO8E=
X-User-Agent: Microsoft Outl00k, Usenet K00k Editions
X-Mutt: The most widely-used MUA
X-Slrn: Why use anything else?
Bytes: 3150

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.