Wednesday, July 20, 2016

Digest for comp.lang.c++@googlegroups.com - 25 updates in 2 topics

"Öö Tiib" <ootiib@hot.ee>: Jul 19 05:16PM -0700

On Tuesday, 19 July 2016 23:47:51 UTC+3, Jerry Stuckle wrote:
 
> Using '{ .a = 10, .c = 30 }' exposes the private members of the class,
> and is a violation of encapsulation. Additionally, the parameter values
> are not validated, creating a potentially invalid object.
 
Aggregate classes are feature of C++. Usage of aggregate initialization
violates no language rules.
 
> the values to ensure the object is properly constructed, or, if it is
> impossible to construct a valid object at this time, the constructor can
> mark the object as invalid until it has been made valid.
 
Private members of class are not hidden but just not accessible (without
special tricks) for non-friends. When class has private or protected
non static data members then it is not aggregate.
Jerry Stuckle <jstucklex@attglobal.net>: Jul 19 09:41PM -0400

On 7/19/2016 8:16 PM, Öö Tiib wrote:
>> are not validated, creating a potentially invalid object.
 
> Aggregate classes are feature of C++. Usage of aggregate initialization
> violates no language rules.
 
The use of names of private members (which data members in general
should be, according to OO principles) would be a violation of those
principles.
 
 
> Private members of class are not hidden but just not accessible (without
> special tricks) for non-friends. When class has private or protected
> non static data members then it is not aggregate.
 
Exactly. And they would not be accessible to your initialization
syntax, either.
 
But even with private or protected non-static members the class can
still be aggregate. You need to look up the definition of aggregate.
 
For instance, the following would be an aggregate:
 
class Person {
private:
String name;
String address;
Date dob;
...
};
 
It contains (at least) two String and one Date objects.
 
And if data members are not private, you have thrown away one of the
most useful OO principles.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Ian Collins <ian-news@hotmail.com>: Jul 20 01:54PM +1200

On 07/20/16 01:41 PM, Jerry Stuckle wrote:
> syntax, either.
 
> But even with private or protected non-static members the class can
> still be aggregate. You need to look up the definition of aggregate.
 
It's a pity you didn't:
 
ISO/IEC 14882:2011(E) 8.5.1 Aggregates [dcl.init.aggr]
 
1 An aggregate is an array or a class (Clause 9) with no user-provided
constructors (12.1), no brace-or-equal-initializers for non-static data
members (9.2), no private or protected non-static data members (Clause
11), no base classes (Clause 10), and no virtual functions (10.3).
 
--
Ian
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 20 03:58AM +0200

On 20.07.2016 03:41, Jerry Stuckle wrote:
 
> But even with private or protected non-static members the class can
> still be aggregate.
 
Nope.
 
 
> You need to look up the definition of aggregate.
 
C++03 and C++11 §8.5.1/1:
 
"An aggregate is an array or a class (clause 9) with no user-declared
constructors (12.1), no private or protected non-static data members
(clause 11), no base classes (clause 10), and no virtual functions (10.3)"
 
I checked only these two standards because they were open in my PDF reader.
 
Unfortunately, nowaydays it's a hassle to navigate to things on disk in
Windows. :(
 
 
> Date dob;
> ...
> };
 
Nope.
 
 
> It contains (at least) two String and one Date objects.
 
> And if data members are not private, you have thrown away one of the
> most useful OO principles.
 
Different tools can be best for different tasks.
 
 
Cheers & hth.,
 
- Alf (teacher mode (well, I've been paid to do this :) ))
Jerry Stuckle <jstucklex@attglobal.net>: Jul 19 11:49PM -0400

On 7/19/2016 9:54 PM, Ian Collins wrote:
> constructors (12.1), no brace-or-equal-initializers for non-static data
> members (9.2), no private or protected non-static data members (Clause
> 11), no base classes (Clause 10), and no virtual functions (10.3).
 
Try again. That is ONE definition of aggregate. Not by far the only
one. And not accepted by many developers.
 
But then you're always good at quoting specs without understanding the
meaning and/or limitations.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: Jul 19 11:51PM -0400

On 7/19/2016 9:58 PM, Alf P. Steinbach wrote:
 
> Different tools can be best for different tasks.
 
> Cheers & hth.,
 
> - Alf (teacher mode (well, I've been paid to do this :) ))
 
Another one who has no idea what he's talking about. And yes, I was
paid (quite well) to teach before I decided I didn't want to travel any
more.
 
ag·gre·gate
noun
noun: aggregate; plural noun: aggregates
ˈaɡriɡət/
 
1.
a whole formed by combining several (typically disparate) elements.
"the council was an aggregate of three regional assemblies"
the total number of points scored by a player or team in a
series of sporting contests.
"the result put the sides even on aggregate"
synonyms: total, sum total, sum, grand total
"he won with an aggregate of 325"
2.
a material or structure formed from a loosely compacted mass of
fragments or particles.
 
Still applicable to C++, and used the correct way by many programmers.
Not everyone agrees with your definition. Not by a long shot.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
"Öö Tiib" <ootiib@hot.ee>: Jul 19 08:58PM -0700

On Wednesday, 20 July 2016 04:41:27 UTC+3, Jerry Stuckle wrote:
 
> The use of names of private members (which data members in general
> should be, according to OO principles) would be a violation of those
> principles.
 
This thread did not discuss object oriented programming principles
but aggregate initialization of objects.
 
> syntax, either.
 
> But even with private or protected non-static members the class can
> still be aggregate. You need to look up the definition of aggregate.
 
You are wrong but you are incapable of looking things up so I provide
quote:
! [dcl.init.aggr]/1
! An aggregate is an array or a class with no user-provided constructors,
! no private or protected non-static data members, no base classes, and
! no virtual functions.
 
> ...
> };
 
> It contains (at least) two String and one Date objects.
 
Yes, but it is not aggregate.
 
 
> And if data members are not private, you have thrown away one of the
> most useful OO principles.
 
Aggregate classes are widely used by C++ programmers. For example
'std::array' is aggregate. I prefer to use aggregate classes to
'std::tuple' since aggregate can define member functions, can
overload operators and can have useful names for its attributes.
Ian Collins <ian-news@hotmail.com>: Jul 20 04:06PM +1200

On 07/20/16 03:49 PM, Jerry Stuckle wrote:
>> 11), no base classes (Clause 10), and no virtual functions (10.3).
 
> Try again. That is ONE definition of aggregate. Not by far the only
> one.
 
It's the only one pertinent to C++ classes.
 
> And not accepted by many developers.
 
Non-C++ developers presumably.
 
If you can get this to compile, you have a broken compiler...
 
class C { int n; } c {0}; // Not an aggregate
struct S { int n; } s {0}; // Aggregate
 
--
Ian
"Öö Tiib" <ootiib@hot.ee>: Jul 19 09:11PM -0700

On Wednesday, 20 July 2016 06:49:18 UTC+3, Jerry Stuckle wrote:
> > 11), no base classes (Clause 10), and no virtual functions (10.3).
 
> Try again. That is ONE definition of aggregate. Not by far the only
> one. And not accepted by many developers.
 
Also most humans understand "strings" in meaning of female
underwear but that is still irrelevant.
 
 
> But then you're always good at quoting specs without understanding the
> meaning and/or limitations.
 
We were specifically talking about aggregate classes of C++ in topic
about aggregate initialization in a C++ newsgroup.
Juha Nieminen <nospam@thanks.invalid>: Jul 20 09:05AM

> Try again. That is ONE definition of aggregate. Not by far the only
> one. And not accepted by many developers.
 
Yeah. The C++ standard is just a bunch of suggestions, and up to
individual subjective opinions and preferences. It can be safely
ignored.
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Jerry Stuckle <jstucklex@attglobal.net>: Jul 20 10:43AM -0400

On 7/20/2016 12:06 AM, Ian Collins wrote:
 
>> Try again. That is ONE definition of aggregate. Not by far the only
>> one.
 
> It's the only one pertinent to C++ classes.
 
And it violates encapsulation. So it's not a proper object.
 
>> And not accepted by many developers.
 
> Non-C++ developers presumably.
 
Like people who KNOW how to properly encapsulate C++ code.
 
> If you can get this to compile, you have a broken compiler...
 
> class C { int n; } c {0}; // Not an aggregate
> struct S { int n; } s {0}; // Aggregate
 
Ah, but a structure is not an object. So you're not doing OO
programming. You might as well be using C.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: Jul 20 10:44AM -0400

On 7/20/2016 12:11 AM, Öö Tiib wrote:
>> meaning and/or limitations.
 
> We were specifically talking about aggregate classes of C++ in topic
> about aggregate initialization in a C++ newsgroup.
 
That's right. And your definition of aggregate violates basic
encapsulation. So it's not OO programming. You might as well use C.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: Jul 20 10:45AM -0400

On 7/20/2016 5:05 AM, Juha Nieminen wrote:
> individual subjective opinions and preferences. It can be safely
> ignored.
 
> --- news://freenews.netfront.net/ - complaints: news@netfront.net ---
 
It can also be quoted by people who have no idea what they're talking
about. As is done quite often in this newsgroup.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: Jul 20 10:47AM -0400

On 7/19/2016 11:58 PM, Öö Tiib wrote:
>> principles.
 
> This thread did not discuss object oriented programming principles
> but aggregate initialization of objects.
 
In case you haven't learned. C++ is an object oriented programming
language. If you're not going to use OO principles, then you might as
well use C.
 
> ! An aggregate is an array or a class with no user-provided constructors,
> ! no private or protected non-static data members, no base classes, and
> ! no virtual functions.
 
Which is a violation of OO principles. So just use C. It has what you
want.
 
>> };
 
>> It contains (at least) two String and one Date objects.
 
> Yes, but it is not aggregate.
 
Not according to YOUR definition.
 
> 'std::array' is aggregate. I prefer to use aggregate classes to
> 'std::tuple' since aggregate can define member functions, can
> overload operators and can have useful names for its attributes.
 
std::array is not an aggregate class because it does not contain
disparate objects.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
scott@slp53.sl.home (Scott Lurndal): Jul 20 03:31PM


>In case you haven't learned. C++ is an object oriented programming
>language. If you're not going to use OO principles, then you might as
>well use C.
 
It is certainly not uncommon to mix C and C++ in a single project.
 
And, indeed, many data structure definitions are often shared between
C and C++ code (e.g. struct stat). Supporting designated initializers
in C++ would be useful for those cases.
 
And, your first statement is incorrect. C++ can be _used_ as an
object oriented programming language, but it is perfectly legal to use
it as a standard functional language.
Jerry Stuckle <jstucklex@attglobal.net>: Jul 20 11:39AM -0400

On 7/20/2016 11:31 AM, Scott Lurndal wrote:
 
> And, indeed, many data structure definitions are often shared between
> C and C++ code (e.g. struct stat). Supporting designated initializers
> in C++ would be useful for those cases.
 
Yes, and most of those have something to do with the OS or OS-related
calls. Most OS's are language agnostic, and don't have an OO interface.
struct stat is a perfect example of that.
 
> And, your first statement is incorrect. C++ can be _used_ as an
> object oriented programming language, but it is perfectly legal to use
> it as a standard functional language.
 
It is designed as an OO language. Yes, it can be used as a functional
language - but that is not its design, and people shouldn't complain if
it doesn't contain some of the functional language features they want.
 
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 20 05:26PM +0100

On 20/07/2016 15:43, Jerry Stuckle wrote:
>> struct S { int n; } s {0}; // Aggregate
 
> Ah, but a structure is not an object. So you're not doing OO
> programming. You might as well be using C.
 
A class isn't an object either. As far as C++ is concerned the only
difference between struct and class is default access protection level.
And as far as C++ is concerned:
 
int n = 1;
 
'n' is an object.
 
You don't know the basics it seems.
 
/Flibble
Jerry Stuckle <jstucklex@attglobal.net>: Jul 20 04:09PM -0400

On 7/20/2016 12:26 PM, Mr Flibble wrote:
 
> A class isn't an object either. As far as C++ is concerned the only
> difference between struct and class is default access protection level.
> And as far as C++ is concerned:
 
Being anal as usual, I see.
 
 
> 'n' is an object.
 
> You don't know the basics it seems.
 
> /Flibble
 
And you are as anal as ever.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Ian Collins <ian-news@hotmail.com>: Jul 21 08:40AM +1200

On 07/21/16 03:39 AM, Jerry Stuckle wrote:
 
> It is designed as an OO language. Yes, it can be used as a functional
> language - but that is not its design, and people shouldn't complain if
> it doesn't contain some of the functional language features they want.
 
"C++ was designed to support a range of styles that I considered
fundamentally good and useful. Whether they were object-oriented,
and in which sense of the word, was either irrelevant or a minor
concern"
 
http://www.stroustrup.com/oopsla.pdf
 
--
Ian
Ian Collins <ian-news@hotmail.com>: Jul 21 08:45AM +1200

On 07/21/16 02:43 AM, Jerry Stuckle wrote:
>>> one.
 
>> It's the only one pertinent to C++ classes.
 
> And it violates encapsulation. So it's not a proper object.
 
The relevance of this to aggregate initialisation is?
 
>> struct S { int n; } s {0}; // Aggregate
 
> Ah, but a structure is not an object. So you're not doing OO
> programming. You might as well be using C.
 
class C { int n; } c {0}; // Not an aggregate
class S { public: int n; } s {0}; // Aggregate
 
Happy now?
 
--
Ian
Gareth Owen <gwowen@gmail.com>: Jul 20 10:30PM +0100

> fundamentally good and useful. Whether they were object-oriented,
> and in which sense of the word, was either irrelevant or a minor
> concern"
 
Yes, but did Bjarne ever work as a consultant for IBM? Eh? Eh?
 
No.
 
So what does he know.
woodbrian77@gmail.com: Jul 20 03:53PM -0700

On Tuesday, July 19, 2016 at 11:07:02 PM UTC-5, Ian Collins wrote:
 
> > Try again. That is ONE definition of aggregate. Not by far the only
> > one.
 
> It's the only one pertinent to C++ classes.
 
Ouch. That sort of detachment from reality has led
to so many messes in the standard. I think Jerry is
just highlighting another one here.
 
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
Ian Collins <ian-news@hotmail.com>: Jul 21 10:59AM +1200


>> It's the only one pertinent to C++ classes.
 
> Ouch. That sort of detachment from reality has led
> to so many messes in the standard.
 
Do what? So do you regard the standard's definition other words which
have alternative uses in spoken English such as "string" as detachments
from reality? Should the standard refrain from providing specific
definitions and promote a free for all?
 
> I think Jerry is just highlighting another one here.
 
Jerry is being an arse.
 
--
Ian
Juha Nieminen <nospam@thanks.invalid>: Jul 20 09:15AM

Consider the following code:
 
//--------------------------------------------------------
#include <initializer_list>
 
struct A { int x, y; };
struct B { int x, y; std::initializer_list<int> l; };
 
struct Test
{
A a; B b;
constexpr Test(const A& ia): a(ia), b{0,0,{}} {}
constexpr Test(const B& ib): a{0,0}, b(ib) {}
};
 
constexpr B kB { 1, 2, { 1, 2, 3 } };
constexpr Test kTest1 = A { 5, 10 };
constexpr Test kTest2 = B { 5, 10, { 1, 2, 3 } };
 
int main() {}
//--------------------------------------------------------
 
It compiles with gcc, but not with clang. The latter says:
 
//--------------------------------------------------------
test.cc:16:16: error: constexpr variable 'kTest2' must be initialized by a
constant expression
constexpr Test kTest2 = B { 5, 10, { 1, 2, 3 } };
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cc:16:16: note: pointer to subobject of temporary is not a constant
expression
test.cc:16:36: note: temporary created here
constexpr Test kTest2 = B { 5, 10, { 1, 2, 3 } };
^
//--------------------------------------------------------
 
Which one is right?
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Ian Collins <ian-news@hotmail.com>: Jul 20 10:37PM +1200

On 07/20/16 09:15 PM, Juha Nieminen wrote:
> ^
> //--------------------------------------------------------
 
> Which one is right?
 
I think clang is correct. { 1, 2, 3 } is a temporary initializer_list
object.
 
constexpr std::initializer_list<int> il { 1, 2, 3 };
constexpr Test kTest2 = B { 5, 10, il };
 
Should be okay.
--
Ian
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: