473,883 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alias for a std::vector

I am trying to refer to the same std::vector in a class by two different names,
I tried a union, and I tried a reference, I can't seem to get the syntax right.
Can anyone please help? Thanks
Aug 16 '06
56 5850

Peter Olcott wrote:
If you don't already know how to do it, I would guess that I would likely be
wrong. I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple. I would expect that you would know all the
little nuances that I have never learned, so I estimate that I am likely
incorrect.
If you never write a class that has any of:

a const data member
a reference data member
a member of class type that provides no default constructor
a member of class type that provides no assignment operator
a base class that provides no default constructor or for which the
default constructor is not appropriate in your context

and you're not worried about:

possible efficiency problems in default initialising then assigning to
members vs directly initialising as required
possibly violating the principle of least surprise when other people
read your code

then you can avoid using initialiser lists if you want to. But remove
any one of those caveats and you need to use the initialiser list. Once
you are using it for some objects out of necessity, there is a strong
argument for clarity and consistency that you should use it all the
time.

Gavin Deane

Aug 18 '06 #51
In article <RJaFg.1210$Tl4 .311@dukeread06 >,
Peter Olcott <ol****@att.net wrote:
>"Greg Comeau" <co****@panix.c omwrote in message
news:ec******* ***@panix2.pani x.com...
>In article <_30Fg.1162$Tl4 .145@dukeread06 >,
Peter Olcott <ol****@att.net wrote:
>>>"Greg Comeau" <co****@panix.c omwrote in message
news:ec***** *****@panix2.pa nix.com...
I don't understand. What you did was to ignore a cornerstone
feature of initialization because it was deemed bad language
design (why do you think so??) only to introduce same on another

It is bad language design (non orthogonal) because there are two entirely
different syntax ways of doing this. Initialization lists and assignment,
the former being the oddball.

Let's assume this is true. Show us how to do it with assignment only
while still retaining all the semantics necessary. In that
description please also remember than C++ derived from C.

If you don't already know how to do it, I would guess that I would likely be
wrong. I have never needed to use the initializer list syntax until recently,
I try to keep my code very simple. I would expect that you would know all the
little nuances that I have never learned, so I estimate that I am likely
incorrect.
It is important to keep things simple. But
I suspect you've only been using a subset of C++, hence limiting
your C++ programming universe. Nothing wrong with that per se.
But the breadth and width of programming is immense, and C++ captures
various aspects of that. This limiting often results in things being
"not as they should seem." A year later you'll wonder how you ever
thought such things. :)
>>>level. Also, on this note, if the body of the ctor is so far
too large that may also be problematic in its own right.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 18 '06 #52
In article <11************ **********@m73g 2000cwd.googleg roups.com>,
Gavin Deane <de*********@ho tmail.comwrote:
>
Peter Olcott wrote:
>If you don't already know how to do it, I would guess that I would likely be
wrong. I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple. I would expect that you would know all the
little nuances that I have never learned, so I estimate that I am likely
incorrect.

If you never write a class that has any of:

a const data member
a reference data member
a member of class type that provides no default constructor
a member of class type that provides no assignment operator
a base class that provides no default constructor or for which the
default constructor is not appropriate in your context

and you're not worried about:

possible efficiency problems in default initialising then assigning to
members vs directly initialising as required
possibly violating the principle of least surprise when other people
read your code

then you can avoid using initialiser lists if you want to. But remove
any one of those caveats and you need to use the initialiser list. Once
you are using it for some objects out of necessity, there is a strong
argument for clarity and consistency that you should use it all the
time.
Yep. So long as you mention it, folks may also wan tot have a look at
http://www.comeaucomputing.com/techtalk/#meminit
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 18 '06 #53

"Peter Olcott" <ol****@att.net wrote in message
news:RJaFg.1210 $Tl4.311@dukere ad06...
I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple.
For me, the initialization list is the _simpler_ choice. In any new class
that I write, I put everything I can there. I only write code in the body
of the constructor if I _have_ to.

And it seems logical to me, as well as simple. It's stating in explicit
terms exactly what the initial state of the object will be.

Assignments are changes to state, and until an object is initialized, it
doesn't make semantic sense to "change" its state.

(Plus, how would you specify a specific constructor to use in order to
initialize the base class from a derived class constructor, if you didn't
have the initializer list?)

-Howard
Aug 18 '06 #54

"Greg Comeau" <co****@panix.c omwrote in message
news:ec******** **@panix2.panix .com...
In article <d24Fg.1182$Tl4 .813@dukeread06 >,
Peter Olcott <ol****@att.net wrote:
>>Instead of C++ overloading the meaning of the term [initialization]
to make it mean something slightly different than what it means
everywhere else, C++ should have adopted the universal convention
of the meaning of this term.

I believe this is an operative sentence in this discussion.
Therefore, it would be helpful for you to define what the
alledged and/or actual definition is in your opinion. That
might help to reveal why there is a difference of discussion here.
>>If they want to have something slightly different than what
[initialization] means everywhere else, they could come up
with a different term.

You may have a point, but I suspect there is subset relationship
that exists due to to limitations whereby it is oft considered the rule,
but in actuality is "merely" a subset.
>>In any case there is no absolute
requirement for initialization lists, the same semantics could be
derived using the assignment operator.

Let's assume this is true. Show us how. And also why it is superior.
>>In the case of things such as references, this
initializatio n form of assignment would only be valid in declarations.

Hmm, seems to me you're already making special rules while at
the same time arguing such specialiality is unncessary and bad.
I'm certain you said that and I did not misinterpret it.
What I am calling for is to keep the communication conventions as uniform as
possible. Its okay for a language to define specialized operations on the
specialized elements of this language. What is not okay it to add yet another
incompatible meaning to a pre-existing commonly understood term. In other words
don't make the details of explaining aspects of the language any more difficult
than necessary.

Minimizing the divergence of common terminology and programming conventions
minimizes the learning curve, and eliminates wasted time. There is already a
commonly understood meaning and syntax for the initialization of things, don't
make a whole different way of doing this if it is at all possible to avoid.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

Aug 18 '06 #55
In article <1x************ *********@bgtns c05-news.ops.worldn et.att.net>,
Howard <al*****@hotmai l.comwrote:
>"Peter Olcott" <ol****@att.net wrote in message
news:RJaFg.121 0$Tl4.311@duker ead06...
>I have never needed to use the initializer list syntax until recently, I
try to keep my code very simple.

For me, the initialization list is the _simpler_ choice. In any new class
that I write, I put everything I can there. I only write code in the body
of the constructor if I _have_ to.

And it seems logical to me, as well as simple. It's stating in explicit
terms exactly what the initial state of the object will be.

Assignments are changes to state, and until an object is initialized, it
doesn't make semantic sense to "change" its state.

(Plus, how would you specify a specific constructor to use in order to
initialize the base class from a derived class constructor, if you didn't
have the initializer list?)
Exactly.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 19 '06 #56
In article <YMpFg.1481$Tl4 .967@dukeread06 >,
Peter Olcott <ol****@att.net wrote:
>"Greg Comeau" <co****@panix.c omwrote in message
news:ec******* ***@panix2.pani x.com...
>In article <d24Fg.1182$Tl4 .813@dukeread06 >,
Peter Olcott <ol****@att.net wrote:
>>>Instead of C++ overloading the meaning of the term [initialization]
to make it mean something slightly different than what it means
everywhere else, C++ should have adopted the universal convention
of the meaning of this term.

I believe this is an operative sentence in this discussion.
Therefore, it would be helpful for you to define what the
alledged and/or actual definition is in your opinion. That
might help to reveal why there is a difference of discussion here.
>>>If they want to have something slightly different than what
[initialization] means everywhere else, they could come up
with a different term.

You may have a point, but I suspect there is subset relationship
that exists due to to limitations whereby it is oft considered the rule,
but in actuality is "merely" a subset.
>>>In any case there is no absolute
requiremen t for initialization lists, the same semantics could be
derived using the assignment operator.

Let's assume this is true. Show us how. And also why it is superior.
>>>In the case of things such as references, this
initializati on form of assignment would only be valid in declarations.

Hmm, seems to me you're already making special rules while at
the same time arguing such specialiality is unncessary and bad.
I'm certain you said that and I did not misinterpret it.

What I am calling for is to keep the communication conventions as uniform as
possible. Its okay for a language to define specialized operations on the
specialized elements of this language. What is not okay it to add yet another
incompatible meaning to a pre-existing commonly understood term. In other words
don't make the details of explaining aspects of the language any more difficult
than necessary.

Minimizing the divergence of common terminology and programming conventions
minimizes the learning curve, and eliminates wasted time. There is already a
commonly understood meaning and syntax for the initialization of things, don't
make a whole different way of doing this if it is at all possible to avoid.
I think I agree completely with what you just wrote....
certainly as a goal, and hopefully in practice when possible.
I just don't think it is coming into play in this case.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in alpha!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 19 '06 #57

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
17876
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; std::vector<double>::size_type size = src.size(); dest.reserve(size); for (std::vector<int>::size_type i = 0;
32
69726
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: std::vector<int> fun(){ //build the vector v; return v; }
21
2218
by: Peter Olcott | last post by:
I got the previous alias to std::vector working, and found that it takes up the space of a pointer. I want to find a way to do an alias to a std::vector that does not take up any space. Is there any way to do this? (I tried #define Name1 Name2 and it didn't compile)
1
10836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9564
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5793
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4210
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.