Topic: Data member overriding
Author: Marc Thibault <marc.thibault1977@gmail.com>
Date: Sun, 18 Nov 2012 09:40:22 -0800 (PST)
Raw View
------=_Part_619_9124742.1353260422548
Content-Type: text/plain; charset=ISO-8859-1
With the addition of the override keyword, there are a few simple
situations where overriding of data member could be interesting.
*1- Overriding of Unions
*It would be interesting to be able to override a union member with any
type that is part of the union. We could do something like this:
class Base {
union {
int i;
float f;
} value;
public:
virtual float toFloat() const= 0;
};
class IntDerived : public Base {
int value override;
public:
float toFloat() const {
return static_cast<float>(value);
}
};
class FloatDerived : public Base {
float value override;
public:
float toFloat() const {
return value;
}
};
Also the member of an union could be unnamed when they are not to be
accessed in the base class.
*2- Overriding of any type with a trivial destructor and no member function
*It would allow to write something like this:
class Base {
std::aligned_storage<32,16> value; //a type with trivial dtor and no
member function?
public:
virtual ~Base() noexcept {}
virtual std::string toString() const= 0;
};
class StringDerived : public Base {
std::string value override;
public:
~StringDerived() noexcept {}
std::string toString() const {
return value;
}
};
class CharArrayDerived : public Base {
char value[32] override;
public:
~CharArrayDerived() noexcept {}
std::string toString() const {
return std::string(value);
}
};
*3**- Define void as a basic abstract type that must be overridden in order
to have a non-abstact type
*A member of type void would have the size an alignment of char but it
would be unreadable and unwritable. It would allow to write this:
class Base {
void value[sizeof(long long)] alignas(long long); //Base is an abstract
class because of this declaration.
public:
virtual double toDouble() const= 0;
};
class IntDerived : public Base {
long long value override;
public:
double toDouble() const {
return static_cast<double>(value);
}
};
class FloatDerived : public Base {
double value override;
public:
double toDouble() const {
return value;
}
};
*Conclusion
*Theses possibilities should allow to hide the implementation of a class
without paying the cost of the pimpl idiom. Also, it seems easier to use and
read than placement new.
--
------=_Part_619_9124742.1353260422548
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
With the addition of the override keyword, there are a few simple situation=
s where overriding of data member could be interesting. <br><br><b><font si=
ze=3D"4"><font size=3D"4">1- Overriding o<font size=3D"4">f Unions<br></fon=
t></font></font></b><font size=3D"4"><font size=3D"4"><font size=3D"4"><fon=
t size=3D"2">It would be interesting to<font size=3D"2"> be able to overrid=
e a union member with any type that is part of the union. We could do somet=
hing li<font size=3D"2">ke this:</font></font></font><br><br><font size=3D"=
2"><span style=3D"font-family: courier new,monospace;">class Base {<br>&nbs=
p; union {<br><font size=3D"2"> &n=
bsp; int i;<br><font size=3D"2"> &=
nbsp; float</font> f;<br><font size=3D"2"> }</font> value=
;<br><br><font size=3D"2"> public:<br><font size=3D"2">&n=
bsp; <font size=3D"2">virtual float toFloat()<font size=3D"2"> =
const=3D 0;</font></font></font><br></font></font></span></font></font></fo=
nt></font><font size=3D"2"><span style=3D"font-family: courier new,monospac=
e;">};<br><br><font size=3D"2">class IntDerived : public Base {<br><font si=
ze=3D"2"> int value override;<br><font size=3D"2"> &=
nbsp; public:<br><font size=3D"2"> float toFloat()<=
/font> const {<br> return static_=
cast<float>(value);<br><font size=3D"2"> }</font><b=
r></font><font size=3D"2">};<br><br><font size=3D"2">class FloatDerived : p=
ublic Base {<br> float value override;<br><font size=3D"2=
"> public:<br><font size=3D"2"> <font s=
ize=3D"2">float to<font size=3D"2">Float() const {<br> &nb=
sp; return value;<br><font size=3D"2"> =
<font size=3D"2">}</font></font><br></font></font></font></font></font></fo=
nt></font></font></span></font><font size=3D"2">};</font><br><br>Also the m=
ember of an union could be <font size=3D"2">unnamed</font> when they are no=
t to be accessed in the base class<font size=3D"2">.</font><br><br><b><font=
size=3D"4">2- Overriding of any type with a trivial destructo<font size=3D=
"4">r and no member function<font size=3D"4"><br></font></font></font></b><=
font size=3D"4"><font size=3D"4"><font size=3D"4"><font size=3D"2">It would=
allow to write something like this:<br><br><font face=3D"courier new,monos=
pace"><font size=3D"2">class Base {<br> std::aligned_st<f=
ont size=3D"2">orage<32,16> value; //a <font size=3D"2">type with <fo=
nt size=3D"2">trivial<font size=3D"2"> dtor and no member function?</font><=
/font></font><br> public:<br> virtual <=
font size=3D"2">~Base() noexcept {}</font><br> <font size=
=3D"2">virtual std::string toString() const=3D 0;</font><br></font></font><=
/font></font></font></font><font size=3D"2">};</font><br><br><font size=3D"=
2">class String<font size=3D"2">Derived : public Base {<br> &nbs=
p; std::string value override;<br><font size=3D"2"> publi=
c:<br><font size=3D"2"> ~StringDerived() noexcept {}<br><=
font size=3D"2"> std::string toString() const {<br> =
return value;<br><font size=3D"2">&nbs=
p; }</font><br></font></font>};<br><br><font size=3D"2">class <=
font size=3D"2">CharArr<font size=3D"2">ayDerived : public Base {<br> =
char value[32]<font size=3D"2"> override;<br><font size=3D"2">=
public:<br><font size=3D"2"> ~CharArra=
yDerived() noexcept {}<br><font size=3D"2"> std::string t=
oString() const {<br><font size=3D"2"> &=
nbsp; retu<font size=3D"2">rn s<font size=3D"2">td::<font size=3D"2">s<font=
size=3D"2">tring(value)<font size=3D"2">;</font></font></font></font></fon=
t></font></font></font></font></font></font></font></font></font></font></f=
ont></font><br><font size=3D"2"> }</font><br><font size=
=3D"2">};</font><br><font size=3D"4"><font size=3D"4"><font size=3D"4"><fon=
t size=3D"2"><font size=3D"2"><font face=3D"courier new,monospace"><font si=
ze=3D"2"><br><font size=3D"4"><font face=3D"arial,sans-serif"><b>3</b><font=
size=3D"4"><font size=3D"4"><font size=3D"2"><font size=3D"2"><font size=
=3D"2"><font size=3D"2"><b><font size=3D"4">- <font size=3D"4">Define void =
as a basic<font size=3D"4"> abstract type that must be <font size=3D"4">ove=
rridden</font> in o<font size=3D"4">rder to <font size=3D"4">have a non-abs=
ta<font size=3D"4">ct type<br></font></font></font></font></font></font></b=
></font></font></font></font></font></font></font></font></font></font></fo=
nt><font size=3D"4"><font size=3D"4"><font size=3D"4"><font size=3D"4"><fon=
t size=3D"4"><font size=3D"4"><font size=3D"2"><font size=3D"2"><font size=
=3D"2">A <font size=3D"2">member of type void would have the size an alignm=
ent of<font size=3D"2"> char but it would be unreadable and unwritable.<fon=
t size=3D"2"> It would al<font size=3D"2">low to write this:<br><br><font s=
ize=3D"2"><font face=3D"courier new,monospace">class Base {<br><font size=
=3D"2"> void <font size=3D"2">value[<font size=3D"2">size=
of(long long)] alignas(</font></font></font>long long); //<font size=3D"2">=
Base is a<font size=3D"2">n abstract class <font size=3D"2">because of this=
declaration.</font></font></font><br><font size=3D"2"> p=
ublic:<br><font size=3D"2"> virtual double toDouble() con=
st=3D 0;</font></font><br><font size=3D"2">}; <br><br><font size=3D"2">clas=
s IntDerived : public Base {<br><font size=3D"2"> long lo=
ng value override;<br><font size=3D"2"> public:<br><font =
size=3D"2"> double toDouble() const {<br> &nbs=
p; return static<font size=3D"2">_cast<<font siz=
e=3D"2">double>(value);</font></font><br><font size=3D"2"> &n=
bsp; }</font></font></font></font></font></font></font></font></font></font=
></font></font></font></font></font></font></font></font></font></font></fo=
nt></font></font></font></font><br><font size=3D"2">};</font><br><br><font =
size=3D"2">class<font size=3D"2"> FloatDerived : public Base {<br> &nb=
sp; double value override;<br><font size=3D"2"> pub=
lic:<br><font size=3D"2"> double toDouble() const {<br>&n=
bsp; return value;<br><font size=3D"2">=
}</font><br></font></font><font size=3D"2">};</font><br>=
</font></font><br><br><b><font size=3D"4">Conclusion<br></font></b><font si=
ze=3D"4"><font size=3D"2"><font size=3D"2">Th<font size=3D"2">eses possibil=
it<font size=3D"2">ies should allo<font size=3D"2">w to hide the implementa=
tion of a <font size=3D"2">class <font size=3D"2"><font size=3D"2">without<=
/font> paying the cost of <font size=3D"2">the pimpl idiom<font size=3D"2">=
.. Also, <font size=3D"2">it seems easier to use <font size=3D"2">and read t=
han placement n<font size=3D"2">ew.</font></font></font></font></font></fon=
t></font></font></font></font></font></font></font><br><br>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_619_9124742.1353260422548--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 18 Nov 2012 10:03:23 -0800 (PST)
Raw View
------=_Part_107_24117092.1353261803826
Content-Type: text/plain; charset=ISO-8859-1
On Sunday, November 18, 2012 9:40:22 AM UTC-8, Marc Thibault wrote:
>
> With the addition of the override keyword, there are a few simple
> situations where overriding of data member could be interesting.
>
> *1- Overriding of Unions
> *It would be interesting to be able to override a union member with any
> type that is part of the union. We could do something like this:
>
> class Base {
> union {
> int i;
> float f;
> } value;
>
> public:
> virtual float toFloat() const= 0;
> };
>
> class IntDerived : public Base {
> int value override;
> public:
> float toFloat() const {
> return static_cast<float>(value);
> }
> };
>
> class FloatDerived : public Base {
> float value override;
> public:
> float toFloat() const {
> return value;
> }
> };
>
> Also the member of an union could be unnamed when they are not to be
> accessed in the base class.
>
> *2- Overriding of any type with a trivial destructor and no member
> function
> *It would allow to write something like this:
>
> class Base {
> std::aligned_storage<32,16> value; //a type with trivial dtor and no
> member function?
> public:
> virtual ~Base() noexcept {}
> virtual std::string toString() const= 0;
> };
>
> class StringDerived : public Base {
> std::string value override;
> public:
> ~StringDerived() noexcept {}
> std::string toString() const {
> return value;
> }
> };
>
> class CharArrayDerived : public Base {
> char value[32] override;
> public:
> ~CharArrayDerived() noexcept {}
> std::string toString() const {
> return std::string(value);
> }
> };
>
> *3**- Define void as a basic abstract type that must be overridden in order
> to have a non-abstact type
> *A member of type void would have the size an alignment of char but it
> would be unreadable and unwritable. It would allow to write this:
>
> class Base {
> void value[sizeof(long long)] alignas(long long); //Base is an
> abstract class because of this declaration.
> public:
> virtual double toDouble() const= 0;
> };
>
> class IntDerived : public Base {
> long long value override;
> public:
> double toDouble() const {
> return static_cast<double>(value);
> }
> };
>
> class FloatDerived : public Base {
> double value override;
> public:
> double toDouble() const {
> return value;
> }
> };
>
>
> *Conclusion
> *Theses possibilities should allow to hide the implementation of a class
> without paying the cost of the pimpl idiom. Also, it seems easier to use and
> read than placement new.
>
If that's the whole point of this stuff, I would much rather we just let
the modules proposal take it's course. After all, Pimpl exists for the sole
purpose of minimizing compile times, which modules will do far better.
--
------=_Part_107_24117092.1353261803826
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Sunday, November 18, 2012 9:40:22 AM UTC-8, Marc Thibault wrote:=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;">With the addition of the overr=
ide keyword, there are a few simple situations where overriding of data mem=
ber could be interesting. <br><br><b><font size=3D"4"><font size=3D"4">1- O=
verriding o<font size=3D"4">f Unions<br></font></font></font></b><font size=
=3D"4"><font size=3D"4"><font size=3D"4"><font size=3D"2">It would be inter=
esting to<font size=3D"2"> be able to override a union member with any type=
that is part of the union. We could do something li<font size=3D"2">ke thi=
s:</font></font></font><br><br><font size=3D"2"><span style=3D"font-family:=
courier new,monospace">class Base {<br> union {<br><font =
size=3D"2"> int i;<br><font size=
=3D"2"> float</font> f;<br><font =
size=3D"2"> }</font> value;<br><br><font size=3D"2"> =
; public:<br><font size=3D"2"> <font size=3D"=
2">virtual float toFloat()<font size=3D"2"> const=3D 0;</font></font></font=
><br></font></font></span></font></font></font></font><font size=3D"2"><spa=
n style=3D"font-family:courier new,monospace">};<br><br><font size=3D"2">cl=
ass IntDerived : public Base {<br><font size=3D"2"> int v=
alue override;<br><font size=3D"2"> public:<br><font size=
=3D"2"> float toFloat()</font> const {<br> &nb=
sp; return static_cast<float>(value);<br><fon=
t size=3D"2"> }</font><br></font><font size=3D"2">};<br><=
br><font size=3D"2">class FloatDerived : public Base {<br>  =
; float value override;<br><font size=3D"2"> public:<br><=
font size=3D"2"> <font size=3D"2">float to<font size=3D"2=
">Float() const {<br> return valu=
e;<br><font size=3D"2"> <font size=3D"2">}</font></font><=
br></font></font></font></font></font></font></font></font></span></font><f=
ont size=3D"2">};</font><br><br>Also the member of an union could be <font =
size=3D"2">unnamed</font> when they are not to be accessed in the base clas=
s<font size=3D"2">.</font><br><br><b><font size=3D"4">2- Overriding of any =
type with a trivial destructo<font size=3D"4">r and no member function<font=
size=3D"4"><br></font></font></font></b><font size=3D"4"><font size=3D"4">=
<font size=3D"4"><font size=3D"2">It would allow to write something like th=
is:<br><br><font face=3D"courier new,monospace"><font size=3D"2">class Base=
{<br> std::aligned_st<font size=3D"2">orage<32,16>=
value; //a <font size=3D"2">type with <font size=3D"2">trivial<font size=
=3D"2"> dtor and no member function?</font></font></font><br> &n=
bsp; public:<br> virtual <font size=3D"2">~Base() noexcep=
t {}</font><br> <font size=3D"2">virtual std::string toSt=
ring() const=3D 0;</font><br></font></font></font></font></font></font></fo=
nt><font size=3D"2">};</font><br><br><font size=3D"2">class String<font siz=
e=3D"2">Derived : public Base {<br> std::string value ove=
rride;<br><font size=3D"2"> public:<br><font size=3D"2">&=
nbsp; ~StringDerived() noexcept {}<br><font size=3D"2"> &n=
bsp; std::string toString() const {<br> =
return value;<br><font size=3D"2"> }</font><=
br></font></font>};<br><br><font size=3D"2">class <font size=3D"2">CharArr<=
font size=3D"2">ayDerived : public Base {<br> char value[=
32]<font size=3D"2"> override;<br><font size=3D"2"> publi=
c:<br><font size=3D"2"> ~CharArrayDerived() noexcept {}<b=
r><font size=3D"2"> std::string toString() const {<br><fo=
nt size=3D"2"> retu<font size=3D"=
2">rn s<font size=3D"2">td::<font size=3D"2">s<font size=3D"2">tring(value)=
<font size=3D"2">;</font></font></font></font></font></font></font></font><=
/font></font></font></font></font></font></font></font><br><font size=3D"2"=
> }</font><br><font size=3D"2">};</font><br><font size=3D=
"4"><font size=3D"4"><font size=3D"4"><font size=3D"2"><font size=3D"2"><fo=
nt face=3D"courier new,monospace"><font size=3D"2"><br><font size=3D"4"><fo=
nt face=3D"arial,sans-serif"><b>3</b><font size=3D"4"><font size=3D"4"><fon=
t size=3D"2"><font size=3D"2"><font size=3D"2"><font size=3D"2"><b><font si=
ze=3D"4">- <font size=3D"4">Define void as a basic<font size=3D"4"> abstrac=
t type that must be <font size=3D"4">overridden</font> in o<font size=3D"4"=
>rder to <font size=3D"4">have a non-absta<font size=3D"4">ct type<br></fon=
t></font></font></font></font></font></b></font></font></font></font></font=
></font></font></font></font></font></font></font></font></font></font><fon=
t size=3D"4"><font size=3D"4"><font size=3D"4"><font size=3D"4"><font size=
=3D"4"><font size=3D"4"><font size=3D"2"><font size=3D"2"><font size=3D"2">=
A <font size=3D"2">member of type void would have the size an alignment of<=
font size=3D"2"> char but it would be unreadable and unwritable.<font size=
=3D"2"> It would al<font size=3D"2">low to write this:<br><br><font size=3D=
"2"><font face=3D"courier new,monospace">class Base {<br><font size=3D"2">&=
nbsp; void <font size=3D"2">value[<font size=3D"2">sizeof(long =
long)] alignas(</font></font></font>long long); //<font size=3D"2">Base is =
a<font size=3D"2">n abstract class <font size=3D"2">because of this declara=
tion.</font></font></font><br><font size=3D"2"> public:<b=
r><font size=3D"2"> virtual double toDouble() const=3D 0;=
</font></font><br><font size=3D"2">}; <br><br><font size=3D"2">class IntDer=
ived : public Base {<br><font size=3D"2"> long long value=
override;<br><font size=3D"2"> public:<br><font size=3D"=
2"> double toDouble() const {<br> =
return static<font size=3D"2">_cast<<font size=3D"2">=
double>(value);</font></font><br><font size=3D"2"> }</=
font></font></font></font></font></font></font></font></font></font></font>=
</font></font></font></font></font></font></font></font></font></font><br><=
font size=3D"2">};</font><br><br><font size=3D"2">class<font size=3D"2"> Fl=
oatDerived : public Base {<br> double value override;<br>=
<font size=3D"2"> public:<br><font size=3D"2">  =
; double toDouble() const {<br> &n=
bsp; return value;<br><font size=3D"2"> }</font><br></fon=
t></font><font size=3D"2">};</font><br></font></font><br><br><b><font size=
=3D"4">Conclusion<br></font></b><font size=3D"4"><font size=3D"2"><font siz=
e=3D"2">Th<font size=3D"2">eses possibilit<font size=3D"2">ies should allo<=
font size=3D"2">w to hide the implementation of a <font size=3D"2">class <f=
ont size=3D"2"><font size=3D"2">without</font> paying the cost of <font siz=
e=3D"2">the pimpl idiom<font size=3D"2">. Also, <font size=3D"2">it seems e=
asier to use <font size=3D"2">and read than placement n<font size=3D"2">ew.=
</font></font></font></font></font></font></font></font></font></font></fon=
t></font></font><br></blockquote><div><br>If that's the whole point of this=
stuff, I would much rather we just let the modules proposal take it's cour=
se. After all, Pimpl exists for the sole purpose of minimizing compile time=
s, which modules will do far better. <br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_107_24117092.1353261803826--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 18 Nov 2012 20:11:36 +0200
Raw View
On 18 November 2012 20:03, Nicol Bolas <jmckesson@gmail.com> wrote:
> If that's the whole point of this stuff, I would much rather we just let the
> modules proposal take it's course. After all, Pimpl exists for the sole
> purpose of minimizing compile times, which modules will do far better.
That's interesting, I use pimpls often and compile times are not the reason -
stable size and ABI of the interface class are.
For this proposal, can you just do it with a buffer in the base class
and a reference
of the right type in a derived class?
--
.
Author: Jean-Marc Bourguet <jm.bourguet@gmail.com>
Date: Sun, 18 Nov 2012 10:22:44 -0800 (PST)
Raw View
------=_Part_377_28612883.1353262964705
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Le dimanche 18 novembre 2012 19:03:24 UTC+1, Nicol Bolas a =E9crit :
>
>
> If that's the whole point of this stuff, I would much rather we just let=
=20
> the modules proposal take it's course. After all, Pimpl exists for the so=
le=20
> purpose of minimizing compile times, which modules will do far better.=20
>
I fail to see how modules will prevent recompilation when the interface=20
changes, so pimpl will still be useful for that purpose. And I'm with Ville=
=20
in that the implication on compilation time is not the only goal of keeping=
=20
a stable interface (I've an idea about how to achieve that with modules=20
without using pimpl, but it isn't achievable with what is in the papers=20
I've seen).
Yours,
--=20
Jean-Marc
--=20
------=_Part_377_28612883.1353262964705
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Le dimanche 18 novembre 2012 19:03:24 UTC+1, Nicol Bolas a =E9crit :<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><br><div>If that's the whole poi=
nt of this stuff, I would much rather we just let the modules proposal take=
it's course. After all, Pimpl exists for the sole purpose of minimizing co=
mpile times, which modules will do far better. <br></div></blockquote><div>=
<br>I fail to see how modules will prevent recompilation when the interface=
changes, so pimpl will still be useful for that purpose. And I'm with Vill=
e in that the implication on compilation time is not the only goal of keepi=
ng a stable interface (I've an idea about how to achieve that with modules =
without using pimpl, but it isn't achievable with what is in the papers I'v=
e seen).<br><br>Yours,<br><br>-- <br>Jean-Marc<br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_377_28612883.1353262964705--
.
Author: Marc Thibault <marc.thibault1977@gmail.com>
Date: Sun, 18 Nov 2012 10:25:06 -0800 (PST)
Raw View
------=_Part_123_16636187.1353263106382
Content-Type: text/plain; charset=ISO-8859-1
I think you're right, with modules most of the problem would get resolved.
But there is another problem that I would like to see solved. It is the
ability to instantiate a container with a base type and store value of a
derived type. In the examples above, all of the derived types could in
theory be stored in a uninitialized buffer of the base type. But the
proposal might need some adjustments, like the ability to declare
std::vector<void[8] alignas(8)>. I think I have made a premature post. I
will try to think about it a little bit more.
--
------=_Part_123_16636187.1353263106382
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
I think you're right, with modules most of the problem would get resolved. =
But there is another problem that I would like to see solved. It is the abi=
lity to instantiate a container with a base type and store value of a deriv=
ed type. In the examples above, all of the derived types could in theory be=
stored in a uninitialized buffer of the base type. But the proposal might =
need some adjustments, like the ability to declare std::vector<void[8] a=
lignas(8)>. I think I have made a premature post. I will try to think ab=
out it a little bit more.<br>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_123_16636187.1353263106382--
.
Author: Marc Thibault <marc.thibault1977@gmail.com>
Date: Sun, 18 Nov 2012 10:35:45 -0800 (PST)
Raw View
------=_Part_3_30571175.1353263745946
Content-Type: text/plain; charset=ISO-8859-1
It would be interesting if this code gave the expected result.
class Base {
void value[8] alignas(8);
public:
Base& operator=(const Base&)=default;
virtual std::string toString() const= 0;
};
class IntDerived : public Base {
long long value override;
public:
std::string toString() const {
return std::to_string(value);
}
};
class FloatDerived: public Base {
double value override;
public:
std::string toString() const {
return std::to_string(value);
}
};
int main()
{
Base array[2];
array[0]= IntDerived();
array[1]= FloatDerived();
return 0;
}
In this case, Base is an abstract class with an abstract member data, and
both derived class have the same size.
--
------=_Part_3_30571175.1353263745946
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
It would be interesting if this code gave the expected result.<br><br><font=
face=3D"courier new,monospace">class Base {<br> void val=
ue[8] alignas(8);<br> public:<br> Base&=
amp; operator=3D(const Base&)=3Ddefault;<br> virtual =
std::string toString() const=3D 0;<br>};<br><br>class IntDerived : public B=
ase {<br> long long value override;<br> =
public:<br> std::string toString() const {<br> &nbs=
p; return std::to_string(value);<br> &nb=
sp; }<br>};<br><br>class FloatDerived: public Base {<br> &=
nbsp; double value override;<br> public:<br> &=
nbsp; std::string toString() const {<br>  =
; return std::to_string(value);<br> }<br>};<br><br>=
int main()<br>{<br> Base array[2];<br> =
array[0]=3D IntDerived();<br> array[1]=3D FloatDerived();=
<br> return 0;<br>}<br><br><font face=3D"arial,sans-serif=
">In this case, Base is an abstract class with an abstract member data, and=
both derived class have the same size.</font><br></font>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_3_30571175.1353263745946--
.
Author: Marc Thibault <marc.thibault1977@gmail.com>
Date: Sun, 18 Nov 2012 10:44:27 -0800 (PST)
Raw View
------=_Part_63_4044018.1353264267241
Content-Type: text/plain; charset=ISO-8859-1
I forgot... dynamic displatch of function could be the default for a class
with an abstract data member, so it would add this extra tool in the
toolbox.
--
------=_Part_63_4044018.1353264267241
Content-Type: text/html; charset=ISO-8859-1
<font face="courier new,monospace">I forgot... dynamic displatch of function could be the default for a class with an abstract data member, so it would add this extra tool in the toolbox.</font><br>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_63_4044018.1353264267241--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 18 Nov 2012 11:02:42 -0800 (PST)
Raw View
------=_Part_1257_1678792.1353265362647
Content-Type: text/plain; charset=ISO-8859-1
On Sunday, November 18, 2012 10:35:46 AM UTC-8, Marc Thibault wrote:
>
> It would be interesting if this code gave the expected result.
>
> class Base {
> void value[8] alignas(8);
> public:
> Base& operator=(const Base&)=default;
> virtual std::string toString() const= 0;
> };
>
> class IntDerived : public Base {
> long long value override;
> public:
> std::string toString() const {
> return std::to_string(value);
> }
> };
>
> class FloatDerived: public Base {
> double value override;
> public:
> std::string toString() const {
> return std::to_string(value);
> }
> };
>
> int main()
> {
> Base array[2];
> array[0]= IntDerived();
> array[1]= FloatDerived();
> return 0;
> }
>
> In this case, Base is an abstract class with an abstract member data, and
> both derived class have the same size.
>
This is confusing. You say that `Base` is an abstract class. But you can't
instantiate an abstract class. Thus `Beta array[2];` should give a compiler
error.
Furthermore, even if it compiled, you can't store a derived class in a base
class object. You can store a reference or pointer to a derived class in a
base class reference or pointer. But you can't do `Base value = Derived{}`.
At least, not without slicing.
Most important of all, if you need this, just use aligned storage:
class Base
{
private:
std::aligned_storage<8, 8>::type storage;
public:
virtual std::string toString() const= 0;
};
class IntDerived : public Base
{
private:
int &value;
public:
IntDerived() : value(reinterpret_cast<int>(&storage)) {}
IntDerived(const IntDerived &t) : value(reinterpret_cast<int>(&storage))
{}
IntDerived operator=(const IntDerived &t) {storage = t.storage;}
virtual std::string toString() const override {return std::to_string(value
);}
};
--
------=_Part_1257_1678792.1353265362647
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Sunday, November 18, 2012 10:35:46 AM UTC-8, Marc Thibault wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;">It would be interesting if th=
is code gave the expected result.<br><br><font face=3D"courier new,monospac=
e">class Base {<br> void value[8] alignas(8);<br> &n=
bsp; public:<br> Base& operator=3D(const Base&a=
mp;)=3Ddefault;<br> virtual std::string toString() const=
=3D 0;<br>};<br><br>class IntDerived : public Base {<br> =
long long value override;<br> public:<br> &nbs=
p; std::string toString() const {<br> &n=
bsp; return std::to_string(value);<br> }<br>};<br><br>cla=
ss FloatDerived: public Base {<br> double value override;=
<br> public:<br> std::string toString()=
const {<br> return std::to_strin=
g(value);<br> }<br>};<br><br>int main()<br>{<br> &nb=
sp; Base array[2];<br> array[0]=3D IntDerived();<br=
> array[1]=3D FloatDerived();<br> retur=
n 0;<br>}<br><br><font face=3D"arial,sans-serif">In this case, Base is an a=
bstract class with an abstract member data, and both derived class have the=
same size.</font><br></font></blockquote><div><br>This is confusing. You s=
ay that `Base` is an abstract class. But you can't instantiate an abstract =
class. Thus `Beta array[2];` should give a compiler error.<br><br>Furthermo=
re, even if it compiled, you can't store a derived class in a base class ob=
ject. You can store a reference or pointer to a derived class in a base cla=
ss reference or pointer. But you can't do `Base value =3D Derived{}`.<br><b=
r>At least, not without slicing.<br><br>Most important of all, if you need =
this, just use aligned storage:<br><br><div class=3D"prettyprint" style=3D"=
background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bor=
der-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D=
"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Base</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">private</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br> std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">aligned_storage</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">8</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: #066;" class=3D"=
styled-by-prettify">8</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">>::</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">type storage</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">pu=
blic</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">string</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> toString</span><span style=3D"colo=
r: #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><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettif=
y">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><spa=
n 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">class</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">IntDerived</span><span style=3D"color: #00=
0;" 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"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">public</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Base</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan 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: #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> </span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">int</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-=
prettify">value</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">public</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: #606;" class=3D"styled-by-prettify">IntDerived</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"> value</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">reinterpret_cast</span><span style=3D"color: #080;" class=
=3D"styled-by-prettify"><int></span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(&</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">storage</span><span style=3D"color: #660;" class=3D"st=
yled-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>&nb=
sp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">IntDer=
ived</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">IntDerived</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: #00=
0;" class=3D"styled-by-prettify">t</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> va=
lue</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">reinterpret_cast=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify"><int>=
;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(&</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">storage</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">))</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{}</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br> </span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">IntDerived</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D(</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">IntDerived</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">t</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=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">storage </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> t</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">storage</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbs=
p; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">string</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> toString</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: #008;"=
class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">override</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #008;" class=3D"styled-by-prettify">retu=
rn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">to_string</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">value</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: #660;" clas=
s=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></div></code></div><br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_1257_1678792.1353265362647--
.
Author: Marc Thibault <marc.thibault1977@gmail.com>
Date: Sun, 18 Nov 2012 11:21:19 -0800 (PST)
Raw View
------=_Part_586_25062501.1353266479312
Content-Type: text/plain; charset=ISO-8859-1
If you take boost::variant, I think you can store those values in an array.
It could be interesting if an abstract class with an abstract member data
was recognized as a something similar to boost::variant.
--
------=_Part_586_25062501.1353266479312
Content-Type: text/html; charset=ISO-8859-1
If you take boost::variant, I think you can store those values in an array. It could be interesting if an abstract class with an abstract member data was recognized as a something similar to boost::variant.<br>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_586_25062501.1353266479312--
.
Author: Marc Thibault <marc.thibault1977@gmail.com>
Date: Sun, 18 Nov 2012 11:25:05 -0800 (PST)
Raw View
------=_Part_323_1192946.1353266705504
Content-Type: text/plain; charset=ISO-8859-1
In fact, one problem with the standard as it is. An array of virtual
objects will store a virtual pointer for each of these objects even if they
are all equal. It would interesting if it was possible to store objects
with different virtual tables without the use of pointers.
--
------=_Part_323_1192946.1353266705504
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
In fact, one problem with the standard as it is. An array of virtual object=
s will store a virtual pointer for each of these objects even if they are a=
ll equal. It would interesting if it was possible to store objects with dif=
ferent virtual tables without the use of pointers.<br>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_323_1192946.1353266705504--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 18 Nov 2012 11:51:13 -0800 (PST)
Raw View
------=_Part_149_29009034.1353268273814
Content-Type: text/plain; charset=ISO-8859-1
On Sunday, November 18, 2012 11:25:05 AM UTC-8, Marc Thibault wrote:
>
> In fact, one problem with the standard as it is. An array of virtual
> objects will store a virtual pointer for each of these objects even if they
> are all equal. It would interesting if it was possible to store objects
> with different virtual tables without the use of pointers.
>
Absolutely not. First, you're assuming that there are "virtual pointers" in
them at all. vtables are not mandated by the standard, nor is that likely
to happen. It may be the most common implementation of virtual dispatch,
but it is not the only one and the standard isn't about to play favorites.
Second, you can't have a *value* that's not of the type it says it is.
sizeof(Base) does not have to be sizeof(ThingDerivedFromBase). Therefore,
any `Base value;` is only big enough to hold `Base`, not necessarily
anything derived from it. And who's to say that some derived class, even if
it doesn't add members, will be the same size? Should the standard mandate
that? To what end?
Just use pointers. Make them unique_ptr if you want. Polymorphic values
would be very strange alongside static typing.
--
------=_Part_149_29009034.1353268273814
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On Sunday, November 18, 2012 11:25:05 AM UTC-8, Marc Thibault wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;">In fact, one problem with the standar=
d as it is. An array of virtual objects will store a virtual pointer for ea=
ch of these objects even if they are all equal. It would interesting if it =
was possible to store objects with different virtual tables without the use=
of pointers.<br></blockquote><div><br>Absolutely not. First, you're assumi=
ng that there are "virtual pointers" in them at all. vtables are not mandat=
ed by the standard, nor is that likely to happen. It may be the most common=
implementation of virtual dispatch, but it is not the only one and the sta=
ndard isn't about to play favorites.<br><br>Second, you can't have a <i>val=
ue</i> that's not of the type it says it is. sizeof(Base) does not have to =
be sizeof(ThingDerivedFromBase). Therefore, any `Base value;` is only big e=
nough to hold `Base`, not necessarily anything derived from it. And who's t=
o say that some derived class, even if it doesn't add members, will be the =
same size? Should the standard mandate that? To what end?<br><br>Just use p=
ointers. Make them unique_ptr if you want. Polymorphic values would be very=
strange alongside static typing.<br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_149_29009034.1353268273814--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 18 Nov 2012 12:04:34 -0800 (PST)
Raw View
------=_Part_552_3065296.1353269074628
Content-Type: text/plain; charset=ISO-8859-1
On Sunday, November 18, 2012 11:21:19 AM UTC-8, Marc Thibault wrote:
>
> If you take boost::variant, I think you can store those values in an
> array. It could be interesting if an abstract class with an abstract member
> data was recognized as a something similar to boost::variant.
>
boost::variant is not something that is "recognized" by the compiler. It is
a class that uses casting and its own form of std::aligned_union to achieve
its results. Pretty much like the above code.
Also, boost::variant is always one of its constituent types. Its default
constructor will default construct one of those types. That's why it works.
Just like the above code. So it's not instantiating an "abstract class" at
all; it's instantiating a *concrete* one.
--
------=_Part_552_3065296.1353269074628
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On Sunday, November 18, 2012 11:21:19 AM UTC-8, Marc Thibault wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;">If you take boost::variant, I think y=
ou can store those values in an array. It could be interesting if an abstra=
ct class with an abstract member data was recognized as a something similar=
to boost::variant.<br></blockquote><div><br>boost::variant is not somethin=
g that is "recognized" by the compiler. It is a class that uses casting and=
its own form of std::aligned_union to achieve its results. Pretty much lik=
e the above code.<br><br>Also, boost::variant is always one of its constitu=
ent types. Its default constructor will default construct one of those type=
s. That's why it works. Just like the above code. So it's not instantiating=
an "abstract class" at all; it's instantiating a <i>concrete</i> one.<br><=
/div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_552_3065296.1353269074628--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 18 Nov 2012 21:03:52 -0800 (PST)
Raw View
------=_Part_190_30018744.1353301432868
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On Sunday, November 18, 2012 10:22:44 AM UTC-8, Jean-Marc Bourguet wrote:
>
> Le dimanche 18 novembre 2012 19:03:24 UTC+1, Nicol Bolas a =E9crit :
>>
>>
>> If that's the whole point of this stuff, I would much rather we just let=
=20
>> the modules proposal take it's course. After all, Pimpl exists for the s=
ole=20
>> purpose of minimizing compile times, which modules will do far better.=
=20
>>
>
> I fail to see how modules will prevent recompilation when the interface=
=20
> changes, so pimpl will still be useful for that purpose. And I'm with Vil=
le=20
> in that the implication on compilation time is not the only goal of keepi=
ng=20
> a stable interface (I've an idea about how to achieve that with modules=
=20
> without using pimpl, but it isn't achievable with what is in the papers=
=20
> I've seen).
>
Modules won't prevent recompilation if the contents of a class change. But=
=20
it will make recompilation faster. If you have a class that is used in=20
2,000 cpp files and you change it, you have to compile those 2,000 cpp=20
files *and every header they each include*. If they all include `<vector>`,=
=20
then you will compile `<vector>` 2,000 times even though it did not change.=
=20
With modules, you only compile the *actual* contents of those 2,000 cpp=20
files, which will be *far* faster. Most of the cpp compilation time is=20
header compiling, which will no longer be necessary.
It doesn't make recompilation unnecessary; it simply means you won't mind=
=20
quite so much when it happens.
That being said, the ABI point is still valid, though how important that is=
=20
depends on how many classes need to have a stable ABI vs. the number that=
=20
don't (ie: which ones are used in the interface and which ones aren't).
BTW, if you do have that idea for modules, you should see that it finds its=
=20
way to the modules study group. No point in keeping it to yourself.
=20
>
> Yours,
>
> --=20
> Jean-Marc
>
--=20
------=_Part_190_30018744.1353301432868
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Sunday, November 18, 2012 10:22:44 AM UTC-8, Jean-Marc Bourguet =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;">Le dimanche 18 novembre =
2012 19:03:24 UTC+1, Nicol Bolas a =E9crit :<blockquote class=3D"gmail=
_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><br><div>If that's the whole point of this stuff, I would muc=
h rather we just let the modules proposal take it's course. After all, Pimp=
l exists for the sole purpose of minimizing compile times, which modules wi=
ll do far better. <br></div></blockquote><div><br>I fail to see how modules=
will prevent recompilation when the interface changes, so pimpl will still=
be useful for that purpose. And I'm with Ville in that the implication on =
compilation time is not the only goal of keeping a stable interface (I've a=
n idea about how to achieve that with modules without using pimpl, but it i=
sn't achievable with what is in the papers I've seen).<br></div></blockquot=
e><div><br>Modules won't prevent recompilation if the contents of a class c=
hange. But it will make recompilation faster. If you have a class that is u=
sed in 2,000 cpp files and you change it, you have to compile those 2,000 c=
pp files <i>and every header they each include</i>. If they all include `&l=
t;vector>`, then you will compile `<vector>` 2,000 times even thou=
gh it did not change. With modules, you only compile the <i>actual</i> cont=
ents of those 2,000 cpp files, which will be <i>far</i> faster. Most of the=
cpp compilation time is header compiling, which will no longer be necessar=
y.<br><br>It doesn't make recompilation unnecessary; it simply means you wo=
n't mind quite so much when it happens.<br><br>That being said, the ABI poi=
nt is still valid, though how important that is depends on how many classes=
need to have a stable ABI vs. the number that don't (ie: which ones are us=
ed in the interface and which ones aren't).<br><br>BTW, if you do have that=
idea for modules, you should see that it finds its way to the modules stud=
y group. No point in keeping it to yourself.<br> </div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div><br>Yours,<br><br>-- <br>Jean-Marc<br></=
div></blockquote>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_190_30018744.1353301432868--
.