Topic: Disallow calling static method on class instance


Author: andreas.sommer87@googlemail.com
Date: Fri, 21 Nov 2014 01:41:10 -0800 (PST)
Raw View
------=_Part_182_1767379552.1416562870473
Content-Type: multipart/alternative;
 boundary="----=_Part_183_354325160.1416562870474"

------=_Part_183_354325160.1416562870474
Content-Type: text/plain; charset=UTF-8

Hey all,

I today encountered the following problem:

class MyClass
{
public:
    MyClass() {}

    static MyClass fromASCII(const char* asciiStr) { return MyClass(asciiStr
); }
    static MyClass fromEBCDIC(const char* str) { return MyClass(
someConversion(str)); }
    static MyClass fromUTF16(const wchar_t* utf16Str) { return MyClass(
doSomeConversion(utf16Str)); }
private:
    MyClass(const std::string& utf8String) { /* ... */ }
};


This is a contrived class with only "static constructors", for example
static methods where the developer has to explicitly state the input string
encoding (doesn't matter for what I'm asking).

Now there are two possible ways to call those constructors:

   1. MyClass c = MyClass::fromASCII("bla"); // correct
   2. MyClass c; c.fromASCII("bam"); // wrong usage but still compiles

I have found that 2) is probably allowed for historical reasons (
http://stackoverflow.com/a/11977427/245706), but cannot think of any case
where it makes sense.

Unfortunately there's also no good way to circumvent this, e.g. to trigger
a compiler error in case 2). None of the options I found made me happy:

   - __attribute__((warn_unused_result)) would result in a compiler warning
   (which could be turned to an error if attribute used wisely), but only
   works on unixy compilers (GCC/Clang, not on MSVC). It's no problem to
   create a cross-platform macro for this, but then I don't get any compiler
   warnings/errors with MSVC.
   - Rewrite to 'friend' functions. That would change the interface for
   developers, i.e. the "fromXYZ" methods would be moved to somewhere else.
   - Aliasing the static methods with non-static method of matching
   signature (e.g. "private: MyClass fromASCII(const char* asciiStr, int
   unused=0)") doesn't work because compiler will then raise an error in both
   1) and 2) because of ambiguous method resolution. And it looks horrible.
   - Implementing public, non-static variants as well. That would confuse
   everyone.
   - Using a namespace named "MyClass" that contains the static
   constructors. Doesn't build because same name cannot be used.
   - I'm having wild dreams of enable_if<is_static_method_call> but that's
   unrealistic... :P

Any other ideas? Do you think it makes sense to have a feature/change to
disallow static method calls on an instance?

Thanks,

Andreas Sommer

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_183_354325160.1416562870474
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hey all,<br><br>I today encountered the following problem:=
<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250,=
 250); border-color: rgb(187, 187, 187); border-style: solid; border-width:=
 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"sub=
prettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">clas=
s</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">public</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">MyClass</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{}</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">static</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">M=
yClass</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fro=
mASCII</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> asciiStr</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">asciiStr</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">static</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">MyClass</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> fromEBCDIC</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">char</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> str</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">My=
Class</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">someConversion=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">str</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">));</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">static</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">MyClass</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> fromUTF16</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">wchar_t=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> utf16Str</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">MyClass</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">doSom=
eConversion</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">utf16Str=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">));</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">private</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">MyClass</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">::</span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>string</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> utf8Str=
ing</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800=
;" class=3D"styled-by-prettify">/* ... */</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span></div></code></div><br><br>This is a contrived class with only =
"static constructors", for example static methods where the developer has t=
o explicitly state the input string encoding (doesn't matter for what I'm a=
sking).<br><br>Now there are two possible ways to call those constructors:<=
br><ol><li><span style=3D"font-family: courier new,monospace;">MyClass c =
=3D MyClass::fromASCII("bla"); // correct</span><br></li><li><span style=3D=
"font-family: courier new,monospace;">MyClass c; c.fromASCII("bam"); // wro=
ng usage but still compiles</span></li></ol><p>I have found that 2) is prob=
ably allowed for historical reasons (<a href=3D"http://stackoverflow.com/a/=
11977427/245706">http://stackoverflow.com/a/11977427/245706</a>), but canno=
t think of any case where it makes sense.</p><p>Unfortunately there's also =
no good way to circumvent this, e.g. to trigger a compiler error in case 2)=
.. None of the options I found made me happy:</p><ul><li>__attribute__((warn=
_unused_result)) would result in a compiler warning (which could be turned =
to an error if attribute used wisely), but only works on unixy compilers (G=
CC/Clang, not on MSVC). It's no problem to create a cross-platform macro fo=
r this, but then I don't get any compiler warnings/errors with MSVC.<br></l=
i><li>Rewrite to 'friend' functions. That would change the interface for de=
velopers, i.e. the "fromXYZ" methods would be moved to somewhere else.<br><=
/li><li>Aliasing the static methods with non-static method of matching sign=
ature (e.g. "private: MyClass fromASCII(const char* asciiStr, int unused=3D=
0)") doesn't work because compiler will then raise an error in both 1) and =
2) because of ambiguous method resolution. And it looks horrible.</li><li>I=
mplementing public, non-static variants as well. That would confuse everyon=
e.</li><li>Using a namespace named "MyClass" that contains the static const=
ructors. Doesn't build because same name cannot be used.</li><li>I'm having=
 wild dreams of enable_if&lt;is_static_method_call&gt; but that's unrealist=
ic... :P</li></ul><p>Any other ideas? Do you think it makes sense to have a=
 feature/change to disallow static method calls on an instance?</p><p>Thank=
s,</p><p>Andreas Sommer<br></p></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_183_354325160.1416562870474--
------=_Part_182_1767379552.1416562870473--

.


Author: "Daniel Gutson" <danielgutson@gmail.com>
Date: Fri, 21 Nov 2014 13:01:06 +0000
Raw View
--part2180-boundary-81988234-308261908
Content-Type: text/plain; charset=UTF-8

What about (private) static methods called by nonstatic methods? For example, a helper conversion function that happens that does not depend on the state of the object, and something specific enough to not to put it out of the class.
This is a very common idiom.
Would you prohibit its usage depending on the visibility access? Hmmm...
-----Original Message-----
From: andreas.sommer87@googlemail.com
Date: Fri, 21 Nov 2014 01:41:10
To: <std-proposals@isocpp.org>
Reply-To: std-proposals@isocpp.org
Subject: [std-proposals] Disallow calling static method on class instance

Hey all,

I today encountered the following problem:

class MyClass
{
public:
    MyClass() {}

    static MyClass fromASCII(const char* asciiStr) { return MyClass(asciiStr
); }
    static MyClass fromEBCDIC(const char* str) { return MyClass(
someConversion(str)); }
    static MyClass fromUTF16(const wchar_t* utf16Str) { return MyClass(
doSomeConversion(utf16Str)); }
private:
    MyClass(const std::string& utf8String) { /* ... */ }
};


This is a contrived class with only "static constructors", for example
static methods where the developer has to explicitly state the input string
encoding (doesn't matter for what I'm asking).

Now there are two possible ways to call those constructors:

   1. MyClass c = MyClass::fromASCII("bla"); // correct
   2. MyClass c; c.fromASCII("bam"); // wrong usage but still compiles

I have found that 2) is probably allowed for historical reasons (
http://stackoverflow.com/a/11977427/245706), but cannot think of any case
where it makes sense.

Unfortunately there's also no good way to circumvent this, e.g. to trigger
a compiler error in case 2). None of the options I found made me happy:

   - __attribute__((warn_unused_result)) would result in a compiler warning
   (which could be turned to an error if attribute used wisely), but only
   works on unixy compilers (GCC/Clang, not on MSVC). It's no problem to
   create a cross-platform macro for this, but then I don't get any compiler
   warnings/errors with MSVC.
   - Rewrite to 'friend' functions. That would change the interface for
   developers, i.e. the "fromXYZ" methods would be moved to somewhere else.
   - Aliasing the static methods with non-static method of matching
   signature (e.g. "private: MyClass fromASCII(const char* asciiStr, int
   unused=0)") doesn't work because compiler will then raise an error in both
   1) and 2) because of ambiguous method resolution. And it looks horrible.
   - Implementing public, non-static variants as well. That would confuse
   everyone.
   - Using a namespace named "MyClass" that contains the static
   constructors. Doesn't build because same name cannot be used.
   - I'm having wild dreams of enable_if<is_static_method_call> but that's
   unrealistic... :P

Any other ideas? Do you think it makes sense to have a feature/change to
disallow static method calls on an instance?

Thanks,

Andreas Sommer

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--part2180-boundary-81988234-308261908
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><=
meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type"></h=
ead><body>What about (private) static methods called by nonstatic methods? =
For example, a helper conversion function that happens that does not depend=
 on the state of the object, and something specific enough to not to put it=
 out of the class.<br/>This is a very common idiom.<br/>Would you prohibit =
its usage depending on the visibility access? Hmmm...<hr/><div><b>From: </b=
> andreas.sommer87@googlemail.com
</div><div><b>Date: </b>Fri, 21 Nov 2014 01:41:10 -0800 (PST)</div><div><b>=
To: </b>&lt;std-proposals@isocpp.org&gt;</div><div><b>ReplyTo: </b> std-pro=
posals@isocpp.org
</div><div><b>Subject: </b>[std-proposals] Disallow calling static method o=
n class instance</div><div><br/></div><div dir=3D"ltr">Hey all,<br><br>I to=
day encountered the following problem:<br><br><div class=3D"prettyprint" st=
yle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 18=
7); border-style: solid; border-width: 1px; word-wrap: break-word;"><code c=
lass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">MyClass</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">publ=
ic</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;=
 </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{}</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">static</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">MyClass</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> fromASCII</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">char</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> as=
ciiStr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">MyClass</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">asciiStr</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp=
; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">static</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> fromEBCDIC</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">char</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> str</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">MyClass</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">someConversion</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">str</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">));</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">stati=
c</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> fromUTF16</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">wchar_t</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> utf16Str</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">doSomeConversion</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">utf16Str</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">));</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
private</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &=
nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyCl=
ass</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">string</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> utf8String</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/* =
.... */</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br><b=
r>This is a contrived class with only "static constructors", for example st=
atic methods where the developer has to explicitly state the input string e=
ncoding (doesn't matter for what I'm asking).<br><br>Now there are two poss=
ible ways to call those constructors:<br><ol><li><span style=3D"font-family=
: courier new,monospace;">MyClass c =3D MyClass::fromASCII("bla"); // corre=
ct</span><br></li><li><span style=3D"font-family: courier new,monospace;">M=
yClass c; c.fromASCII("bam"); // wrong usage but still compiles</span></li>=
</ol><p>I have found that 2) is probably allowed for historical reasons (<a=
 href=3D"http://stackoverflow.com/a/11977427/245706">http://stackoverflow.c=
om/a/11977427/245706</a>), but cannot think of any case where it makes sens=
e.</p><p>Unfortunately there's also no good way to circumvent this, e.g. to=
 trigger a compiler error in case 2). None of the options I found made me h=
appy:</p><ul><li>__attribute__((warn_unused_result)) would result in a comp=
iler warning (which could be turned to an error if attribute used wisely), =
but only works on unixy compilers (GCC/Clang, not on MSVC). It's no problem=
 to create a cross-platform macro for this, but then I don't get any compil=
er warnings/errors with MSVC.<br></li><li>Rewrite to 'friend' functions. Th=
at would change the interface for developers, i.e. the "fromXYZ" methods wo=
uld be moved to somewhere else.<br></li><li>Aliasing the static methods wit=
h non-static method of matching signature (e.g. "private: MyClass fromASCII=
(const char* asciiStr, int unused=3D0)") doesn't work because compiler will=
 then raise an error in both 1) and 2) because of ambiguous method resoluti=
on. And it looks horrible.</li><li>Implementing public, non-static variants=
 as well. That would confuse everyone.</li><li>Using a namespace named "MyC=
lass" that contains the static constructors. Doesn't build because same nam=
e cannot be used.</li><li>I'm having wild dreams of enable_if&lt;is_static_=
method_call&gt; but that's unrealistic... :P</li></ul><p>Any other ideas? D=
o you think it makes sense to have a feature/change to disallow static meth=
od calls on an instance?</p><p>Thanks,</p><p>Andreas Sommer<br></p></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

</body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--part2180-boundary-81988234-308261908--


.


Author: andreas.sommer87@googlemail.com
Date: Fri, 21 Nov 2014 05:29:17 -0800 (PST)
Raw View
------=_Part_363_380331976.1416576557225
Content-Type: multipart/alternative;
 boundary="----=_Part_364_1328187160.1416576557225"

------=_Part_364_1328187160.1416576557225
Content-Type: text/plain; charset=UTF-8

Hmm no, that's surely a necessary and handy idiom. But would be nice to
manually disallow calling a certain static method. Guess it's not really
feasible to only have it forbidden when doing calls "from outside".

On Friday, November 21, 2014 2:01:10 PM UTC+1, dgutson wrote:
>
> What about (private) static methods called by nonstatic methods? For
> example, a helper conversion function that happens that does not depend on
> the state of the object, and something specific enough to not to put it out
> of the class.
> This is a very common idiom.
> Would you prohibit its usage depending on the visibility access? Hmmm...
> ------------------------------
> *From: * andreas....@googlemail.com <javascript:>
> *Date: *Fri, 21 Nov 2014 01:41:10 -0800 (PST)
> *To: *<std-pr...@isocpp.org <javascript:>>
> *ReplyTo: * std-pr...@isocpp.org <javascript:>
> *Subject: *[std-proposals] Disallow calling static method on class
> instance
>
> Hey all,
>
> I today encountered the following problem:
>
> class MyClass
> {
> public:
>     MyClass() {}
>
>     static MyClass fromASCII(const char* asciiStr) { return MyClass(
> asciiStr); }
>     static MyClass fromEBCDIC(const char* str) { return MyClass(
> someConversion(str)); }
>     static MyClass fromUTF16(const wchar_t* utf16Str) { return MyClass(
> doSomeConversion(utf16Str)); }
> private:
>     MyClass(const std::string& utf8String) { /* ... */ }
> };
>
>
> This is a contrived class with only "static constructors", for example
> static methods where the developer has to explicitly state the input string
> encoding (doesn't matter for what I'm asking).
>
> Now there are two possible ways to call those constructors:
>
>    1. MyClass c = MyClass::fromASCII("bla"); // correct
>    2. MyClass c; c.fromASCII("bam"); // wrong usage but still compiles
>
> I have found that 2) is probably allowed for historical reasons (
> http://stackoverflow.com/a/11977427/245706), but cannot think of any case
> where it makes sense.
>
> Unfortunately there's also no good way to circumvent this, e.g. to trigger
> a compiler error in case 2). None of the options I found made me happy:
>
>    - __attribute__((warn_unused_result)) would result in a compiler
>    warning (which could be turned to an error if attribute used wisely), but
>    only works on unixy compilers (GCC/Clang, not on MSVC). It's no problem to
>    create a cross-platform macro for this, but then I don't get any compiler
>    warnings/errors with MSVC.
>    - Rewrite to 'friend' functions. That would change the interface for
>    developers, i.e. the "fromXYZ" methods would be moved to somewhere else.
>    - Aliasing the static methods with non-static method of matching
>    signature (e.g. "private: MyClass fromASCII(const char* asciiStr, int
>    unused=0)") doesn't work because compiler will then raise an error in both
>    1) and 2) because of ambiguous method resolution. And it looks horrible.
>    - Implementing public, non-static variants as well. That would confuse
>    everyone.
>    - Using a namespace named "MyClass" that contains the static
>    constructors. Doesn't build because same name cannot be used.
>    - I'm having wild dreams of enable_if<is_static_method_call> but
>    that's unrealistic... :P
>
> Any other ideas? Do you think it makes sense to have a feature/change to
> disallow static method calls on an instance?
>
> Thanks,
>
> Andreas Sommer
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposal...@isocpp.org <javascript:>.
> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_364_1328187160.1416576557225
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hmm no, that's surely a necessary and handy idiom. But wou=
ld be nice to manually disallow calling a certain static method. Guess it's=
 not really feasible to only have it forbidden when doing calls "from outsi=
de".<br><br>On Friday, November 21, 2014 2:01:10 PM UTC+1, dgutson wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div>What about (private) static=
 methods called by nonstatic methods? For example, a helper conversion func=
tion that happens that does not depend on the state of the object, and some=
thing specific enough to not to put it out of the class.<br>This is a very =
common idiom.<br>Would you prohibit its usage depending on the visibility a=
ccess? Hmmm...<hr><div><b>From: </b> <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"F3BUn6xAe3UJ" onmousedown=3D"this.href=3D'java=
script:';return true;" onclick=3D"this.href=3D'javascript:';return true;">a=
ndreas....@googlemail.<wbr>com</a>
</div><div><b>Date: </b>Fri, 21 Nov 2014 01:41:10 -0800 (PST)</div><div><b>=
To: </b>&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=
=3D"F3BUn6xAe3UJ" onmousedown=3D"this.href=3D'javascript:';return true;" on=
click=3D"this.href=3D'javascript:';return true;">std-pr...@isocpp.org</a>&g=
t;</div><div><b>ReplyTo: </b> <a href=3D"javascript:" target=3D"_blank" gdf=
-obfuscated-mailto=3D"F3BUn6xAe3UJ" onmousedown=3D"this.href=3D'javascript:=
';return true;" onclick=3D"this.href=3D'javascript:';return true;">std-pr..=
..@isocpp.org</a>
</div><div><b>Subject: </b>[std-proposals] Disallow calling static method o=
n class instance</div><div><br></div><div dir=3D"ltr">Hey all,<br><br>I tod=
ay encountered the following problem:<br><br><div style=3D"background-color=
:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-w=
idth:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">class<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">MyClass=
</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">{</=
span><span style=3D"color:#000"><br></span><span style=3D"color:#008">publi=
c</span><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>&=
nbsp; &nbsp; </span><span style=3D"color:#606">MyClass</span><span style=3D=
"color:#660">()</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{}</span><span style=3D"color:#000"><br><br>&nbsp; &nbsp; </span><=
span style=3D"color:#008">static</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">MyClass</span><span style=3D"color:#000"> fromASC=
II</span><span style=3D"color:#660">(</span><span style=3D"color:#008">cons=
t</span><span style=3D"color:#000"> </span><span style=3D"color:#008">char<=
/span><span style=3D"color:#660">*</span><span style=3D"color:#000"> asciiS=
tr</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><=
span style=3D"color:#008">return</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">MyClass</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#000">asciiStr</span><span style=3D"color:#660">);</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">}</span><s=
pan style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#008=
">static</span><span style=3D"color:#000"> </span><span style=3D"color:#606=
">MyClass</span><span style=3D"color:#000"> fromEBCDIC</span><span style=3D=
"color:#660">(</span><span style=3D"color:#008">const</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">char</span><span style=3D"co=
lor:#660">*</span><span style=3D"color:#000"> str</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">{</span><span style=3D"color:#000"> </span><span style=3D"color:#008">re=
turn</span><span style=3D"color:#000"> </span><span style=3D"color:#606">My=
Class</span><span style=3D"color:#660">(</span><span style=3D"color:#000">s=
omeConversion</span><span style=3D"color:#660">(</span><span style=3D"color=
:#000">str</span><span style=3D"color:#660">));</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
><br>&nbsp; &nbsp; </span><span style=3D"color:#008">static</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">MyClass</span><span st=
yle=3D"color:#000"> fromUTF16</span><span style=3D"color:#660">(</span><spa=
n style=3D"color:#008">const</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#008">wchar_t</span><span style=3D"color:#660">*</span><spa=
n style=3D"color:#000"> utf16Str</span><span style=3D"color:#660">)</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">return</span><span =
style=3D"color:#000"> </span><span style=3D"color:#606">MyClass</span><span=
 style=3D"color:#660">(</span><span style=3D"color:#000">doSomeConversion</=
span><span style=3D"color:#660">(</span><span style=3D"color:#000">utf16<wb=
r>Str</span><span style=3D"color:#660">));</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#008">private</span><span style=3D"color:#660">=
:</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"=
color:#606">MyClass</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">const</span><span style=3D"color:#000"> std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#008">string</span><span styl=
e=3D"color:#660">&amp;</span><span style=3D"color:#000"> utf8String</span><=
span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">/* ... */</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#660">};</span><span style=3D"color:#000"><br></span></div></cod=
e></div><br><br>This is a contrived class with only "static constructors", =
for example static methods where the developer has to explicitly state the =
input string encoding (doesn't matter for what I'm asking).<br><br>Now ther=
e are two possible ways to call those constructors:<br><ol><li><span style=
=3D"font-family:courier new,monospace">MyClass c =3D MyClass::fromASCII("bl=
a"); // correct</span><br></li><li><span style=3D"font-family:courier new,m=
onospace">MyClass c; c.fromASCII("bam"); // wrong usage but still compiles<=
/span></li></ol><p>I have found that 2) is probably allowed for historical =
reasons (<a href=3D"http://stackoverflow.com/a/11977427/245706" target=3D"_=
blank" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F=
%2Fstackoverflow.com%2Fa%2F11977427%2F245706\46sa\75D\46sntz\0751\46usg\75A=
FQjCNFEYq-zJLmG7BdiABKEif7t5cnBJA';return true;" onclick=3D"this.href=3D'ht=
tp://www.google.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fa%2F11977427%2=
F245706\46sa\75D\46sntz\0751\46usg\75AFQjCNFEYq-zJLmG7BdiABKEif7t5cnBJA';re=
turn true;">http://stackoverflow.com/a/<wbr>11977427/245706</a>), but canno=
t think of any case where it makes sense.</p><p>Unfortunately there's also =
no good way to circumvent this, e.g. to trigger a compiler error in case 2)=
.. None of the options I found made me happy:</p><ul><li>__attribute__((warn=
_unused_<wbr>result)) would result in a compiler warning (which could be tu=
rned to an error if attribute used wisely), but only works on unixy compile=
rs (GCC/Clang, not on MSVC). It's no problem to create a cross-platform mac=
ro for this, but then I don't get any compiler warnings/errors with MSVC.<b=
r></li><li>Rewrite to 'friend' functions. That would change the interface f=
or developers, i.e. the "fromXYZ" methods would be moved to somewhere else.=
<br></li><li>Aliasing the static methods with non-static method of matching=
 signature (e.g. "private: MyClass fromASCII(const char* asciiStr, int unus=
ed=3D0)") doesn't work because compiler will then raise an error in both 1)=
 and 2) because of ambiguous method resolution. And it looks horrible.</li>=
<li>Implementing public, non-static variants as well. That would confuse ev=
eryone.</li><li>Using a namespace named "MyClass" that contains the static =
constructors. Doesn't build because same name cannot be used.</li><li>I'm h=
aving wild dreams of enable_if&lt;is_static_method_<wbr>call&gt; but that's=
 unrealistic... :P</li></ul><p>Any other ideas? Do you think it makes sense=
 to have a feature/change to disallow static method calls on an instance?</=
p><p>Thanks,</p><p>Andreas Sommer<br></p></div>

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
F3BUn6xAe3UJ" onmousedown=3D"this.href=3D'javascript:';return true;" onclic=
k=3D"this.href=3D'javascript:';return true;">std-proposal...@<wbr>isocpp.or=
g</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"F3BUn6xAe3UJ" onmousedown=3D"this.href=3D'java=
script:';return true;" onclick=3D"this.href=3D'javascript:';return true;">s=
td-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank" onmousedown=3D"this.href=3D'http://groups=
..google.com/a/isocpp.org/group/std-proposals/';return true;" onclick=3D"thi=
s.href=3D'http://groups.google.com/a/isocpp.org/group/std-proposals/';retur=
n true;">http://groups.google.com/a/<wbr>isocpp.org/group/std-<wbr>proposal=
s/</a>.<br>

</div></blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_364_1328187160.1416576557225--
------=_Part_363_380331976.1416576557225--

.


Author: David Krauss <potswa@gmail.com>
Date: Fri, 21 Nov 2014 21:30:36 +0800
Raw View
--Apple-Mail=_A7604790-5CA0-42ED-A5A4-4BF3694E868A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


On 2014=E2=80=9311=E2=80=9321, at 5:41 PM, andreas.sommer87@googlemail.com =
wrote:

> I have found that 2) is probably allowed for historical reasons (http://s=
tackoverflow.com/a/11977427/245706), but cannot think of any case where it =
makes sense.
>=20
One case is a generic method that happens not to need the implicit object a=
rgument, but needs to work with the syntax for the sake of its brethren in =
other classes. The implicit parameter is dead weight.

Another case is when it=E2=80=99s simply more convenient because an object =
is on hand but the type name isn=E2=80=99t. decltype is an ugly alternative=
..
> Unfortunately there's also no good way to circumvent this, e.g. to trigge=
r a compiler error in case 2). None of the options I found made me happy:
>=20
Perhaps overload resolution could be adjusted to prefer the implicit parame=
ter when the object is available. This wouldn=E2=80=99t be a breaking chang=
e because such functions aren=E2=80=99t currently allowed to overload each =
other at all. (EDG seems to disagree with GCC and Clang when the overload s=
et is generated by a using-declaration, though; the latter are more toleran=
t and ignore the inherited overloads.)

Anyway, given such an extension you could define the nonstatic overload as =
deleted, but then you wouldn=E2=80=99t be able to call the static overload =
from inside the class without qualification. You could declare the nonstati=
c overload with protected access but the implementation and resulting diagn=
ostics would be wonky.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_A7604790-5CA0-42ED-A5A4-4BF3694E868A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014=
=E2=80=9311=E2=80=9321, at 5:41 PM, <a href=3D"mailto:andreas.sommer87@goog=
lemail.com">andreas.sommer87@googlemail.com</a> wrote:</div><br class=3D"Ap=
ple-interchange-newline"><blockquote type=3D"cite"><p style=3D"font-family:=
 Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font=
-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto=
; text-align: start; text-indent: 0px; text-transform: none; white-space: n=
ormal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I =
have found that 2) is probably allowed for historical reasons (<a href=3D"h=
ttp://stackoverflow.com/a/11977427/245706">http://stackoverflow.com/a/11977=
427/245706</a>), but cannot think of any case where it makes sense.</p></bl=
ockquote><div>One case is a generic method that happens not to need the imp=
licit object argument, but needs to work with the syntax for the sake of it=
s brethren in other classes. The implicit parameter is dead weight.</div><d=
iv><br></div>Another case is when it=E2=80=99s simply more convenient becau=
se an object is on hand but the type name isn=E2=80=99t. <font face=3D"Cour=
ier">decltype</font> is an ugly alternative.<br><blockquote type=3D"cite"><=
p style=3D"font-family: Helvetica; font-size: 12px; font-style: normal; fon=
t-variant: normal; font-weight: normal; letter-spacing: normal; line-height=
: normal; orphans: auto; text-align: start; text-indent: 0px; text-transfor=
m: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text=
-stroke-width: 0px;">Unfortunately there's also no good way to circumvent t=
his, e.g. to trigger a compiler error in case 2). None of the options I fou=
nd made me happy:</p></blockquote></div>Perhaps overload resolution could b=
e adjusted to prefer the implicit parameter when the object is available. T=
his wouldn=E2=80=99t be a breaking change because such functions aren=E2=80=
=99t currently allowed to overload each other at all. (EDG seems to disagre=
e with GCC and Clang when the overload set is generated by a using-declarat=
ion, though; the latter are more tolerant and ignore the inherited overload=
s.)<div><br></div><div>Anyway, given such an extension you could define the=
 nonstatic overload as deleted, but then you wouldn=E2=80=99t be able to ca=
ll the static overload from inside the class without qualification. You cou=
ld declare the nonstatic overload with <font face=3D"Courier">protected</fo=
nt> access but the implementation and resulting diagnostics would be wonky.=
</div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_A7604790-5CA0-42ED-A5A4-4BF3694E868A--

.


Author: ngkwanti@gmail.com
Date: Fri, 28 Nov 2014 23:53:24 -0800 (PST)
Raw View
------=_Part_5474_1121212474.1417247604901
Content-Type: multipart/alternative;
 boundary="----=_Part_5475_1865062250.1417247604909"

------=_Part_5475_1865062250.1417247604909
Content-Type: text/plain; charset=UTF-8

We can't apply qualifier to a static function, which make sense because
there is no instance to apply the qualifier.

class MyClass
{
public:
    static void Method();
    static void Method() const&; // compile error. no instance
    static void Method() &;      // compile error. no instance
    static void Method() &&;     // compile error. no instance
};

but we also can't overload static function with qualified non-static
function.  I don't understand why need to have this restriction.  Maybe
lack of use case or other reason that I don't know.

class MyClass
{
public:
    static void Method();
    void Method() const&; // compile error. can't overload with static
function
    void Method() &;      // compile error. can't overload with static
function
    void Method() &&;     // compile error. can't overload with static
function
};

void test()
{
    MyClass::Method();    // call static void Method();

    MyClass i;
    i.Method();           // call void Method() &

    MyClass const c;
    c.Method();           // call void Method() const&

    MyClass{}.Method();   // call void Method() &&
}

It will be nice to remove this restriction so that we can overload between
static and non static functions.
There is no ambiguity when calling this overload functions and removing
this restriction will not break existing code.

Then Andreas's problem can be solved like this:

class MyClass
{
public:
    MyClass() {}

    static MyClass fromASCII(const char* asciiStr) { return MyClass(asciiStr
); }
    MyClass fromASCII(const char* asciiStr) & = delete;
    MyClass fromASCII(const char* asciiStr) && = delete;
    MyClass fromASCII(const char* asciiStr) const& = delete;
private:
    MyClass(const std::string& utf8String) { /* ... */ }

I think there is more use case for this kind of overloading.

Regards,
kwanti.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_5475_1865062250.1417247604909
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>We can't apply qualifier to a static function, which =
make sense because there is no instance to apply the qualifier.</div><div><=
br></div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250=
, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><code=
 class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: =
#008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">MyClass</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
public</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">stati=
c</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Method</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">static</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Method</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// compile error. no instanc=
e</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp=
; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">s=
tatic</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Method</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&amp;;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">// compile error. no instance</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">static</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Method</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;&amp;;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> &nbsp; &nbsp; </span><span style=3D"color: #800;" class=3D=
"styled-by-prettify">// compile error. no instance</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span></div></code></div><div><br>but we als=
o can't overload static function with qualified non-static function. &nbsp;=
I don't understand why need to have this restriction. &nbsp;Maybe lack of u=
se case or other reason that I don't know.</div><div><br><div class=3D"pret=
typrint" style=3D"border: 1px solid rgb(187, 187, 187); background-color: r=
gb(250, 250, 250); word-wrap: break-word;"><code class=3D"prettyprint"><div=
 class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyCla=
ss</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">public</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">static</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Method</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Met=
hod</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&amp;;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #8=
00;" class=3D"styled-by-prettify">// compile error. </span><span style=3D"c=
olor: rgb(136, 0, 0);"><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">can't overload with static function</span></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">Method</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&amp;;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">// compile error. </span><span style=3D"color: rgb(136, 0=
, 0);"><span style=3D"color: #800;" class=3D"styled-by-prettify">can't over=
load with static function</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">Method</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp=
;&amp;;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &n=
bsp; &nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// compile error. </span><span style=3D"color: rgb(136, 0, 0);"><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">can't overload with static=
 function</span></span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> test</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">MyClass</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">Method</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> &nbsp; &nbsp;</span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// call static void Method();</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">MyClass</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> i</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; i</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">Method</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// call void Method() &am=
p;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=
&nbsp; &nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">MyClass</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> c</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; c</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Method</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">// call void =
Method() const&amp;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br><br>&nbsp; &nbsp; </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">MyClass</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{}.</span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Method</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 &nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
 call void Method() &amp;&amp;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">}</span></div></code></div><div><br></div>It will be nice to =
remove this restriction so that we can overload between static and non stat=
ic functions.</div><div>There is no ambiguity when calling this overload fu=
nctions and removing this restriction will not break existing code.</div><d=
iv><br></div><div>Then Andreas's problem can be solved like this:</div><div=
><br></div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 2=
50, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">MyClass</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
public</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &n=
bsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyCla=
ss</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{}</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">static</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">MyClass</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> fromASCII</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">char</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 asciiStr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" clas=
s=3D"styled-by-prettify">MyClass</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">asciiStr</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &n=
bsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyCla=
ss</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fromASC=
II</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> asciiStr</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><font color=3D"#666600"><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">delete</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n></font><span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp; &=
nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyCl=
ass</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fromAS=
CII</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> asciiStr</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><font color=3D"#666600"><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">delete</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span></font><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">&nbsp; &nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">MyClass</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> fromASCII</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">char</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> asciiStr</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><font color=3D"#666600"><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">delete</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span></font><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">private</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp=
; &nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">M=
yClass</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">string</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> utf8String</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
* ... */</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></d=
iv></code></div><div><br></div><div>I think there is more use case for this=
 kind of overloading.<span style=3D"font-family: monospace; background-colo=
r: rgb(250, 250, 250); color: rgb(102, 102, 0);"><br></span></div><div><br>=
</div><div>Regards,</div><div>kwanti.</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_5475_1865062250.1417247604909--
------=_Part_5474_1121212474.1417247604901--

.


Author: David Krauss <potswa@gmail.com>
Date: Sat, 29 Nov 2014 15:56:31 +0800
Raw View
--Apple-Mail=_880C4A74-3256-494C-9931-55B8F91C1238
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


On 2014=E2=80=9311=E2=80=9329, at 3:53 PM, ngkwanti@gmail.com wrote:

> I think there is more use case for this kind of overloading.

Your solution is essentially the same as the one I suggested at the end of =
the previous message. It might help promote it if you could illustrate othe=
r uses.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_880C4A74-3256-494C-9931-55B8F91C1238
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014=
=E2=80=9311=E2=80=9329, at 3:53 PM, <a href=3D"mailto:ngkwanti@gmail.com">n=
gkwanti@gmail.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><=
blockquote type=3D"cite"><div style=3D"font-family: Helvetica; font-size: 1=
2px; font-style: normal; font-variant: normal; font-weight: normal; letter-=
spacing: normal; line-height: normal; orphans: auto; text-align: start; tex=
t-indent: 0px; text-transform: none; white-space: normal; widows: auto; wor=
d-spacing: 0px; -webkit-text-stroke-width: 0px;">I think there is more use =
case for this kind of overloading.</div></blockquote></div><br><div>Your so=
lution is essentially the same as the one I suggested at the end of the pre=
vious message. It might help promote it if you could illustrate other uses.=
</div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_880C4A74-3256-494C-9931-55B8F91C1238--

.


Author: ngkwanti@gmail.com
Date: Sat, 29 Nov 2014 03:28:35 -0800 (PST)
Raw View
------=_Part_5211_53876081.1417260515246
Content-Type: multipart/alternative;
 boundary="----=_Part_5212_1404677980.1417260515246"

------=_Part_5212_1404677980.1417260515246
Content-Type: text/plain; charset=UTF-8



> Your solution is essentially the same as the one I suggested at the end of
> the previous message. It might help promote it if you could illustrate
> other uses.
>

After experimenting with the idea, I couldn't find a practical use case
apart from cosmetic one.
Maybe Andreas's one is the only sensible use case for this.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_5212_1404677980.1417260515246
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div styl=
e=3D"word-wrap:break-word"><div>Your solution is essentially the same as th=
e one I suggested at the end of the previous message. It might help promote=
 it if you could illustrate other uses.</div></div></blockquote><div>&nbsp;=
</div><div>After experimenting with the idea, I couldn't find a practical u=
se case apart from cosmetic one.&nbsp;<br></div><div>Maybe Andreas's one is=
 the only sensible use case for this.</div><div><br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_5212_1404677980.1417260515246--
------=_Part_5211_53876081.1417260515246--

.


Author: "Daniel Gutson" <danielgutson@gmail.com>
Date: Sat, 29 Nov 2014 12:10:41 +0000
Raw View
--part3289-boundary-1765491856-1322990996
Content-Type: text/plain; charset=UTF-8

IMHO this can only provide confusion when reading and maintaining a program. Just name the method differently and you'll make a life easier. On the other hand, I don't see a benefit important enough to allow this overloading.
If it would be allowed, I think it would be forbidden in every serious coding guideline (at least, I would forbid it).

  Daniel.
-----Original Message-----
From: ngkwanti@gmail.com
Date: Sat, 29 Nov 2014 03:28:35
To: <std-proposals@isocpp.org>
Reply-To: std-proposals@isocpp.org
Subject: Re: [std-proposals] Re: Disallow calling static method on class instance



> Your solution is essentially the same as the one I suggested at the end of
> the previous message. It might help promote it if you could illustrate
> other uses.
>

After experimenting with the idea, I couldn't find a practical use case
apart from cosmetic one.
Maybe Andreas's one is the only sensible use case for this.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--part3289-boundary-1765491856-1322990996
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><=
meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type"></h=
ead><body>IMHO this can only provide confusion when reading and maintaining=
 a program. Just name the method differently and you'll make a life easier.=
 On the other hand, I don't see a benefit important enough to allow this ov=
erloading.<br/>If it would be allowed, I think it would be forbidden in eve=
ry serious coding guideline (at least, I would forbid it).<br/><br/>  Danie=
l.<hr/><div><b>From: </b> ngkwanti@gmail.com
</div><div><b>Date: </b>Sat, 29 Nov 2014 03:28:35 -0800 (PST)</div><div><b>=
To: </b>&lt;std-proposals@isocpp.org&gt;</div><div><b>ReplyTo: </b> std-pro=
posals@isocpp.org
</div><div><b>Subject: </b>Re: [std-proposals] Re: Disallow calling static =
method on class instance</div><div><br/></div><div dir=3D"ltr"><br><blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-word"><d=
iv>Your solution is essentially the same as the one I suggested at the end =
of the previous message. It might help promote it if you could illustrate o=
ther uses.</div></div></blockquote><div>&nbsp;</div><div>After experimentin=
g with the idea, I couldn't find a practical use case apart from cosmetic o=
ne.&nbsp;<br></div><div>Maybe Andreas's one is the only sensible use case f=
or this.</div><div><br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

</body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--part3289-boundary-1765491856-1322990996--


.