Board index » cppbuilder » Is there in C++ something similar to VisualBasic's "with..."

Is there in C++ something similar to VisualBasic's "with..."


2005-07-29 04:18:16 PM
cppbuilder9
dear builders,
is there something in C++ that is similar to VisualBasic's "with"
operator, so i can set for let's say 100 integers the *same* value
at once like this:
with:
a,b,c,d,e = same_value;
instead of C++'s:
a = same_value;
b = same_value;
c = same_value;
d = same_value;
e = same_value;
....
...
..
.
thanks for any hints on that.....
Oren
 
 

Re:Is there in C++ something similar to VisualBasic's "with..."

Oren Halvani wrote:
Quote
dear builders,

is there something in C++ that is similar to VisualBasic's "with"
operator, so i can set for let's say 100 integers the *same* value
at once like this:

with:

a,b,c,d,e = same_value;

instead of C++'s:

a = same_value;
b = same_value;
c = same_value;
d = same_value;
e = same_value;
....
...
..
.
There's nothing like that. But any program that has 100 different
variables in scope is pretty badly written. What's wrong with an array
and a loop?
Tom
 

Re:Is there in C++ something similar to VisualBasic's "with..."

Oren Halvani wrote:
Quote
is there something in C++ that is similar to VisualBasic's "with"
operator, so i can set for let's say 100 integers the *same* value
at once like this:
I am not sure what "with" does, but I think this will do what you want:
a = b = c = d = e = same_value;
But I would probably use an std::vector instead.
Ivan Johansen
 

{smallsort}

Re:Is there in C++ something similar to VisualBasic's "with..."

"Tom Widmer" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
There's nothing like that. But any program that has 100 different
variables in scope is pretty badly written. What's wrong with an array
and a loop?

Tom
hi tom,
well an array is not the solution because the integers are vary from
38 - 100 (sorry, i've forgot to tell it before..) and as far as i know
arrays have a fixed size, but maybe i should use a vector...
i'll try to figure it out....
anyway, thank you for the info, i thought C++ had maybe a hidden
"with" operator :-)
Oren
 

Re:Is there in C++ something similar to VisualBasic's "with..."

Ivan Johansen schrieb:
Quote

I am not sure what "with" does, but I think this will do what you want:
a = b = c = d = e = same_value;

But I would probably use an std::vector instead.

Ivan Johansen
hi Ivan,
thas really funny :-)
just few seconds before i've read this post i was also
thinking about a vector...(see the earlier post)
yeah, i think this will be the solution..
thank you very much..
Oren
 

Re:Is there in C++ something similar to VisualBasic's "with..."

Oren Halvani < XXXX@XXXXX.COM >wrote:
Quote
[...]
hi tom,

well an array is not the solution because the integers are vary from
38 - 100 (sorry, i've forgot to tell it before..) and as far as i know
arrays have a fixed size, but maybe i should use a vector...
i'll try to figure it out....
That's what 'std::vector<>' was invented for.
Quote
[...]
Oren
Schobi
--
XXXX@XXXXX.COM is never read
I'm Schobi at suespammers dot org
"Coming back to where you started is not the same as never leaving"
Terry Pratchett
 

Re:Is there in C++ something similar to VisualBasic's "with..."

On Fri, 29 Jul 2005 10:18:16 +0200, Oren Halvani wrote:
Quote
a,b,c,d,e = same_value;

instead of C++'s:

a = same_value;
b = same_value;
c = same_value;
d = same_value;
e = same_value;
....
there isn't a "with" but as assignment statements have a value you can
do:
a = b = c = d =e =f = g = some_valuie;
--
liz
 

Re:Is there in C++ something similar to VisualBasic's "with..."

"Liz Albin"
Quote
On Fri, 29 Jul 2005 10:18:16 +0200, Oren Halvani wrote:

>a,b,c,d,e = same_value;
>
>instead of C++'s:
>
>a = same_value;
>b = same_value;
>c = same_value;
>d = same_value;
>e = same_value;
>....

there isn't a "with" but as assignment statements have a value you can
do:

a = b = c = d =e =f = g = some_valuie;
--
liz
The naming of the member function assign of containers has a name that
equates with assignment statements. Why is the algorithms fill and fill_n
not called assign and assign_n? Theres many badly named things in STL.
Fraser.
 

Re:Is there in C++ something similar to VisualBasic's "with..."

"Oren Halvani" < XXXX@XXXXX.COM >writes:
Quote
dear builders,

is there something in C++ that is similar to VisualBasic's "with"
operator, so i can set for let's say 100 integers the *same* value
at once like this:

with:

a,b,c,d,e = same_value;

instead of C++'s:

a = same_value;
b = same_value;
c = same_value;
d = same_value;
e = same_value;
Sure, depending on if types a,b,c,d, and e have "normal" operator=
semantics, or are builtin types, then you can just do this:
a = b = c = d = e = same_value;
--
Chris (TeamB);
 

Re:Is there in C++ something similar to VisualBasic's "with..."

"Chris Uzdavinis (TeamB)"
Quote
"Oren Halvani"

>dear builders,
>
>is there something in C++ that is similar to VisualBasic's "with"
>operator, so i can set for let's say 100 integers the *same* value
>at once like this:
>
>with:
>
>a,b,c,d,e = same_value;
>
>instead of C++'s:
>
>a = same_value;
>b = same_value;
>c = same_value;
>d = same_value;
>e = same_value;

Sure, depending on if types a,b,c,d, and e have "normal" operator=
semantics, or are builtin types, then you can just do this:

a = b = c = d = e = same_value;

--
Chris (TeamB);
More careful writing would have to be done if there was multiple types. For
instance:
float a,c;
int b;
a=b=c=5.6;
std::cout << a << '\n' << b << '\n' << c << '\n';
Outputs:
5
5
5.6
Fraser.
 

Re:Is there in C++ something similar to VisualBasic's "with..."

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
is there something in C++ that is similar to
VisualBasic's "with" operator
No.
Quote
so i can set for let's say 100 integers the *same*
value at once like this:

with:

a,b,c,d,e = same_value;
For simple things like integers, you can do the following:
a = b = c = d = e = value;
Gambit
 

Re:Is there in C++ something similar to VisualBasic's "with..."

Oren Halvani < XXXX@XXXXX.COM >wrote:
Quote

>[...] What's wrong with an array and a loop?

well an array is not the solution because the integers are
vary from 38 - 100 [...] and as far as i know arrays have a
fixed size,
You can dynamically allocate an array of any type and most any
size and you can use a smart pointer in the process as well.
~ JD
 

Re:Is there in C++ something similar to VisualBasic's "with..."

Fraser Ross wrote:
Quote

More careful writing would have to be done if there was multiple
types. For instance:
float a,c;
int b;
a=b=c=5.6;

Someone who did this in production code I care for would probably be
taken out and quietly shot. It may be less compact, but the following
is more obvious about what it is doing.
float a, c;
int b;
a = c = 5.6;
b = 5;
 

Re:Is there in C++ something similar to VisualBasic's "with..."

On Fri, 29 Jul 2005 17:08:14 +0100, Fraser Ross wrote:
Quote
More careful writing would have to be done if there was multiple types. For
instance:
The OP said ints.
--
liz
 

Re:Is there in C++ something similar to VisualBasic's "with..."

"Liz Albin"
Quote
On Fri, 29 Jul 2005 17:08:14 +0100, Fraser Ross wrote:

>More careful writing would have to be done if there was multiple types.
For
>instance:

The OP said ints.
--
liz
Yes but Chris suggested the objects might have multiple builtin types.
Fraser.