473,836 Members | 1,490 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 5833

Peter Olcott wrote:
"Greg Comeau" <co****@panix.c omwrote in message
news:ec******** **@panix2.panix .com...
In article <zIQEg.929$Tl4. 354@dukeread06> , Peter Olcott <ol****@att.net >
wrote:
>"Victor Bazarov" <v.********@com Acast.netwrote in message
news:eb******* ***@news.datema s.de...
Peter Olcott wrote:
[..]
The basic idea works, yet I don't know the required syntax for all of
my other constructors.
What is the syntax for an initializer list when the constructor has
parameters?

What book are you reading that doesn't describe parameterized c-tors
and their initialiser lists????

I figured it out. It was not merely parameterized constructors with
initializati on lists, I have done this before. It was the case where the
constructor has a body far too large to be contained in the declaration. I
intentionall y avoided paying attention to initialization lists because IMO
they
represent bad (non orthogonal) language design.
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.
No Sir, the former is a brilliant, efficient syntax. Why construct an
unitialized object and afterwards provide it with attributes when you
can build it once as required? Or construct an object and have to limit
or fix its attributes? Or loose the ability to construct and object
that requires const attributes.

Constructors are a cornerstone of C++ and init lists simplify the
construction syntax greatly. Ignoring the immense power that an init
list provides is foolhardy. Take as an example a simple template, for a
moment.

template < class T >
class N
{
T m_t;
public:
N( T t ) : m_t( t ) { }
~N() { }
};

int main()
{
N< int n( 10 );
N< double d(11.1);
N< char c( 'a' ); // etc...
}

Init lists are too powerful and yet so simple_to_use to be ignored.

Aug 18 '06 #41
In article <_30Fg.1162$Tl4 .145@dukeread06 >,
Peter Olcott <ol****@att.net wrote:
>"Greg Comeau" <co****@panix.c omwrote in message
news:ec******* ***@panix2.pani x.com...
>In article <zIQEg.929$Tl4. 354@dukeread06> , Peter Olcott <ol****@att.net >
wrote:
>>>"Victor Bazarov" <v.********@com Acast.netwrote in message
news:eb***** *****@news.date mas.de...
Peter Olcott wrote:
[..]
The basic idea works, yet I don't know the required syntax for all of
my other constructors.
What is the syntax for an initializer list when the constructor has
parameter s?

What book are you reading that doesn't describe parameterized c-tors
and their initialiser lists????

I figured it out. It was not merely parameterized constructors with
initializati on lists, I have done this before. It was the case where the
constructo r has a body far too large to be contained in the declaration. I
intentionall y avoided paying attention to initialization lists because IMO
they
represent bad (non orthogonal) language design.

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.
>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 #42
In article <k41Fg.1164$Tl4 .31@dukeread06> , Peter Olcott <ol****@att.net wrote:
>"Thomas J. Gritzan" <Ph************ *@gmx.dewrote in message
news:ec******* **@newsreader2. netcologne.de.. .
>Peter Olcott schrieb:
>>"Greg Comeau" <co****@panix.c omwrote in message
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.

There are "two different syntax ways" for normal types:

int *pi = new int(5);
int i(5); // both: initialize i to 5

i = 5; // assign/reset i to 5

So there are two different ways for class members, too. It is not bad
language design, it is quite necessary.

It is not necessary at all. One syntactic way of specifying anything is all that
is required. Whenever there is more than one syntactic way of specifying
anything, additional unnecessary learning curve is created. Language design
should favor the language user over the compiler writer by the same ratio of
language users to compiler writers, thus if the compiler writer has a 1,000 fold
greater burden to save the language user 0.1% effort, this is a good tradeoff.
The spirit of these are both reasonable tenets to follow.
I just don't see where/why they are coming into play in this discussion.
--
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 #43
In article <_41Fg.1165$Tl4 .941@dukeread06 >,
>
"Gavin Deane" <de*********@ho tmail.comwrote in message
news:11******* *************** @75g2000cwc.goo glegroups.com.. .
>Peter Olcott wrote:
>>"Greg Comeau" <co****@panix.c omwrote in message
<snip>
>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.

You are aware that initialisation and assignment are two entirely
different things aren't you? It seems odd to object that two entirely
different concepts have entirely different syntax.

Initializati on is merely the first assignment.
At best, that sounds like a data-centeric definition.
It's a subset of the issues on the table which need
to be considered.
--
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 #44
"Peter Olcott" <ol****@att.net wrote in message
news:_41Fg.1165 $Tl4.941@dukere ad06...
>
"Gavin Deane" <de*********@ho tmail.comwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.com...
>>
Peter Olcott wrote:
>>"Greg Comeau" <co****@panix.c omwrote in message

<snip>
>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.

You are aware that initialisation and assignment are two entirely
different things aren't you? It seems odd to object that two entirely
different concepts have entirely different syntax.

Gavin Deane

Initialization is merely the first assignment.
Not always true. In some flavors of Basic, for example, variables are
initialized to known values by the program before you do any assignment.
Initialization in other languages is commonly used to refer to the
programming language itself, not the programming, setting variables to known
values.

Such is the fact that in my OS in my compiler if I compile and run in debug
mode the values are initialized to known values (0 for ints and floats,
etc...). In release mode they are not initialized and I have to set them.

Initialization as used in C is refered to as the first assignment because C
variables are not initialized by the operating system so the word was not
used to mean that (except for the statement, "C does not initialized
variables for you").

Now we are in C++ where we can have the language initialize variables for us
with syntax, I.E.
int* MyInt = new int();

That is true initalization, and is not a "first assignment".

You may want initialization to merely mean the first assignment, but the
truth of the matter is, it doesn't merely mean that, and is now more
commonly used in C++ to mean system initialization ( new int() ) or class
initialization of variables ( MyClass::MyClas s(): MyInt( 0 ) {} )
Aug 18 '06 #45

"Greg Comeau" <co****@panix.c omwrote in message
news:ec******** **@panix2.panix .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.pan ix.com...
>>In article <zIQEg.929$Tl4. 354@dukeread06> , Peter Olcott <ol****@att.net >
wrote:
"Victor Bazarov" <v.********@com Acast.netwrote in message
news:eb**** ******@news.dat emas.de...
Peter Olcott wrote:
>[..]
>The basic idea works, yet I don't know the required syntax for all of
>my other constructors.
>What is the syntax for an initializer list when the constructor has
>parameters ?
>
What book are you reading that doesn't describe parameterized c-tors
and their initialiser lists????

I figured it out. It was not merely parameterized constructors with
initializat ion lists, I have done this before. It was the case where the
construct or has a body far too large to be contained in the declaration. I
intentional ly avoided paying attention to initialization lists because IMO
they
represent bad (non orthogonal) language design.

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.
>
>>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 #46
In article <i_2Fg.1174$Tl4 .641@dukeread06 >, ol****@att.net says...

[ ... ]
Initialization, semantically across languages is merely the first assignment.
The fact that C++ has things that can only be initialized and not otherwise
assigned to does not change this fundamental essential semantic meaning.
First of all, what happens "across languages" is pretty much irrelevant.

Second, C++ has two separate operations: assignment and initialization.
The two do different things in different ways under different
circumstances. Yes, some initializations are a lot like assignments --
but others are not.

There is a separate syntax for each as well. Given that they have
different semantics, this seems perfectly reasonable, at least to me.

It should also be noted that in the case of a derived class, an
initialization list can/does specify how the base class sub-part of the
current object is to be initialized:

class base {
int x;
public:
base(int i) : x(i) {}
};

class derived : public base {
int y;
public:
derived(int i, int j) : base(i), y(j) {}
};

Now, it's true that you could assign to y instead of using an assignment
-- but you could not 'assign' to the base, or directly assign to
base::x. It's private, which is specifically intended to prevent that.
Initialization is still simply a special case of assignment.
Rather the contrary. Consider, for one example, invariant objects. An
invariant object is created (initialized) with a value, and by the
nature of the object, that value can never change (vary).

In C++ that's pretty easy to do: you have a public ctor that takes a
parameter specifying the initial value. You also make the asignment
operator private (and usually don't implement it).

Yes, if you wanted to badly enough you could undoubtedly create a
language in which you created a "first-time-only" assignment operator,
and a "subsequent assignments" operator (or whatever you prefer to call
them). In the end, this wouldn't really change much except the spelling
of things though. You still end up with a simple fact: there are some
pretty good reasons to separate the two (the invariant objects mentioned
above being only one of them).

As long as you separate the two, all you're really doing compared to the
current C++ situation is changing the spelling of the names you give to
operators. If you think it's important to spell "initialization " as some
sort of variant of "operator=" , go ahead and design a language that does
so. Unless it has far more than that to attract users, however, don't be
too suprised if you're the only one who ever uses that language though.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Aug 18 '06 #47
Peter Olcott wrote:
"Thomas J. Gritzan" <Ph************ *@gmx.dewrote
>There are "two different syntax ways" for normal types:

int *pi = new int(5);
int i(5); // both: initialize i to 5

i = 5; // assign/reset i to 5

So there are two different ways for class members, too. It is not bad
language design, it is quite necessary.

It is not necessary at all.
It is.
One syntactic way of specifying anything is all that
is required.
Yes. That's why there is one syntactic way for assignment:

x = y;

and one syntactic way for initialization:

int i(5);

Lets say assignment would work for both things, and the first assignment
binds the reference (in normal functions and in constructors as well):

int i, j;
int& ri;
// much code
ri = i; // does it bind the reference to i or does it assign?
// more code
ri = j; // this will assign, doesn't it?

If you comment out the "ri = i;" line, you will change the behaviour of the
"ri = j;" line. This is bad and error phrone.
Whenever there is more than one syntactic way of specifying
anything, additional unnecessary learning curve is created. Language design
should favor the language user over the compiler writer by the same ratio of
language users to compiler writers, thus if the compiler writer has a 1,000 fold
greater burden to save the language user 0.1% effort, this is a good tradeoff.
What should be many times differs to what really is in the world.

--
Thomas
Aug 18 '06 #48
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
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.
--
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 #49
In article <hD4Fg.1185$Tl4 .306@dukeread06 >,
Peter Olcott <ol****@att.net wrote:
>"peter koch" <pe************ ***@gmail.comwr ote in message
news:11******* *************** @75g2000cwc.goo glegroups.com.. .
>Peter Olcott skrev:
>>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. If they
want
to have something slightly different than what [initialization] means
everywhere
else, they could come up with a different term. In any case there is no
absolute
requirement for initialization lists, the same semantics could be derived
using
the assignment operator. In the case of things such as references, this
initializatio n form of assignment would only be valid in declarations.
You simply don't get it. The difference between C++ and most other
languages is that most other languages don't allow you to have special
initialisation : they have only assignment. This is the case in e.g. C
or Pascal (where there is no initialisation) and Java (where the
initialisati on is system-defined). So those other languages do not need
to have a special notion of initialisation precisely because there us
none. This is related to the rules in C++ that guarantee destruction
and that objects always are in a valid state. It is for exactly the
same reason that initialisation-lists are a necessary, clean and
unavoidable part of the syntax.

Why couldn't the same thing be accomplished using the operator=() syntax?
Show us.
--
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 #50

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

Similar topics

20
17862
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
69708
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
2216
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)
0
9813
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10834
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10584
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
9367
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
7782
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
5645
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
5817
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4446
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
4006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.