I have made this little test with std::pair:
test<intt1(1);
test<intt2(2);
std::pair<test< int>,test<int mypair = std::make_pair( t1,t2);
where test is a template class I wrote. It seems a bit cumbersome to
make a pair are there any better way to do it than the above procedure?
Jun 15 '07
18 2060
Rolf Magnus wrote:
Best suggestion ever: Wait a few year until they add that feature to the
language. Then wait another few years until the majority of compilers
actually implement it. Then you can save a few keypresses.
Any better suggestion for saving the few keypresses?
On 2007-06-17 13:20, Juha Nieminen wrote:
Rolf Magnus wrote:
>Best suggestion ever: Wait a few year until they add that feature to the language. Then wait another few years until the majority of compilers actually implement it. Then you can save a few keypresses.
Any better suggestion for saving the few keypresses?
Baltimore's suggestion about using a typedef.
--
Erik Wikström
Erik Wikström wrote:
On 2007-06-17 13:20, Juha Nieminen wrote:
>Rolf Magnus wrote:
>>Best suggestion ever: Wait a few year until they add that feature to the language. Then wait another few years until the majority of compilers actually implement it. Then you can save a few keypresses.
Any better suggestion for saving the few keypresses?
Baltimore's suggestion about using a typedef.
Which - btw- I already made a day before.
Erik Wikström wrote:
> Any better suggestion for saving the few keypresses?
Baltimore's suggestion about using a typedef.
That only saves keypresses if you have to create more than one
pair. With only one it requires more keypresses.
On Jun 17, 2:44 am, Rolf Magnus <ramag...@t-online.dewrote:
Juha Nieminen wrote:
Ian Collins wrote:
desktop wrote: I have made this little test with std::pair:
> test<intt1(1); test<intt2(2); std::pair<test< int>,test<int mypair = std::make_pair( t1,t2);
>where test is a template class I wrote. It seems a bit cumbersome to make a pair are there any better way to do it than the above procedure?
What would you suggest?
Using 'auto' in the upcoming standard?
Best suggestion ever: Wait a few year until they add that feature to the
language. Then wait another few years until the majority of compilers
actually implement it. Then you can save a few keypresses.
Deducing the type of variable from its initializer expression has
already been voted into C++, so as a feature it has already been
added. Moreover, I see little reason why the poster would have to wait
until the "majority" of C++ compilers supported a
On Jun 17, 2:44 am, Rolf Magnus <ramag...@t-online.dewrote:
Juha Nieminen wrote:
Ian Collins wrote:
desktop wrote: I have made this little test with std::pair:
> test<intt1(1); test<intt2(2); std::pair<test< int>,test<int mypair = std::make_pair( t1,t2);
>where test is a template class I wrote. It seems a bit cumbersome to make a pair are there any better way to do it than the above procedure?
What would you suggest?
Using 'auto' in the upcoming standard?
Best suggestion ever: Wait a few year until they add that feature to the
language. Then wait another few years until the majority of compilers
actually implement it. Then you can save a few keypresses.
Actually, deducing the type of variable from its initializer
expression has already been voted into C++, so it's only a matter of
lobbying C++ compiler vendors to support it in their compilers.
Furthermore, I see no reason why the original poster would have to
wait until the "majority" of C++ compilers support this feature -
instead of just the C++ compiler he happens to be using.
I would point out that the "auto" keyword saves a few keystrokes only
if you already know what those keystrokes should be. But figuring out
the return type of a function call may not always be easy (e.g.
boost::bind) or even be possible (in a portable way). What type, for
example, does std::tr1::mem_f n() return:
struct A
{
int f();
};
??? mf = std::tr1::mem_f n( &A::f);
Hint: it's unspecified.
Greg
On Jun 17, 11:44 am, Rolf Magnus <ramag...@t-online.dewrote:
Juha Nieminen wrote:
Ian Collins wrote:
desktop wrote: I have made this little test with std::pair:
> test<intt1(1); test<intt2(2); std::pair<test< int>,test<int mypair = std::make_pair( t1,t2);
>where test is a template class I wrote. It seems a bit cumbersome to make a pair are there any better way to do it than the above procedure?
What would you suggest?
Using 'auto' in the upcoming standard?
Best suggestion ever: Wait a few year until they add that feature to the
language. Then wait another few years until the majority of compilers
actually implement it. Then you can save a few keypresses.
More than keystrokes, I think the point is maintainability .
Modify t1 and t2 to be test<long>, and everything works with
auto.
--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
In article <46************ **********@news .song.fi>, no****@thanks.i nvalid says...
Erik Wikström wrote:
Any better suggestion for saving the few keypresses?
Baltimore's suggestion about using a typedef.
That only saves keypresses if you have to create more than one
pair. With only one it requires more keypresses.
I haven't actually counted characters, but I believe this typedef should
save a few keystrokes even the first time around:
typedef test<intti;
ti t1(1), t2(2);
std::pair<ti, timypair=std::m ake_pair(t1, t2);
--
Later,
Jerry.
The universe is a figment of its own imagination.
"desktop" <ff*@sss.comwro te in message
news:f4******** **@news.net.uni-c.dk...
>I have made this little test with std::pair:
test<intt1(1);
test<intt2(2); std::pair<test< int>,test<int mypair =
std::make_pair( t1,t2);
where test is a template class I wrote. It seems a bit cumbersome to make
a pair are there any better way to do it than the above procedure?
How about
std::pair<test< int>,test<int mypair(t1, t2);
? It might even be that you can write
std::pair<test< int>,test<int mypair(1, 2);
depending on your definition of test. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Neil Zanella |
last post by:
Hello,
I would like to ask how come the design of C++ includes
std::pair. First of all I don't think many programmers
would use it. For starters, what the first and second
members are depends on what you are using the pair
for. For instance if I am using coordinates in two
dimensional space then I like to use x and y. So
I might as well define my own struct with x and
y members in it and create a constructor so
|
by: Stoian |
last post by:
hey how is it goin,
i've got this problem - declared a template but it doesn't work
properly, here is the code:
53 std::map<Config, Config> seen;
54 Config new();
55 seen.insert(new, new);
i need to do it that way but the code brakes when i write the command
"seen.insert(new, new);"
|
by: jd |
last post by:
The following code illustrates a problem I have been trying to get around in
c++. Can anyone explain how I can get this to work. The code compiles
fine if I leave out the lines with the comments after them.
Tnaks in advance for any help.
jd
//file test.cpp:
#include "pair.h"
#include "triple.h"
|
by: Serengeti |
last post by:
Hello,
in my class I have a map that translates strings to pointers to some
member functions. The code goes like this:
class F {
typedef void (Function::*MathFuncPtr)();
std::map<std::string, MathFuncPtr> predefinedFunctions;
// lots of other stuff
void makeDictionary(){ predefinedFunctions=&F::f_sin(); }
};
|
by: Enos Meroka |
last post by:
Hallo,
I am a student doing my project in the university.. I have been trying
to compile the program using HP -UX aCC compiler, however I keep on
getting the following errors.
=================================================================
Error 19: "CORBAManagerMessages.h", line 4 # Unexpected 'std'.
using std::string;
^^^
| |
by: kamaraj80 |
last post by:
Hi
I am using the std:: map as following.
typedef struct _SeatRowCols
{
long nSeatRow;
unsigned char ucSeatLetter;
}SeatRowCols;
typedef struct _NetData
|
by: cesco |
last post by:
I have a set of pairs defined as follow:
set< pair<UserEquipment*, double> > numberOfFreqSlotsToAdd;
and I need to iterate through all the elements of the set in order
accumulate the second field of the pair (that is double). Is there any
way I can use the algorithm accumulate to accomplish this?
The following line of code
double unit = accumulate( numberOfFreqSlotsToAdd.begin(),
|
by: Mona |
last post by:
Newbie question - I am a newbie to c++ and stl maps. My question is
based onSystemC which is a specialized C++ hardware programming
language.
I am trying to create a map with key of type sc_lv<22> (sc_logic vector
with 22 bits) and the value is a class pf packets with 8 different
fields of type sc_lv also.
Here's what I am trying to do -
cur_transactions_p current_pkt_info;
|
by: puzzlecracker |
last post by:
I need to be able to map two string to some value in the map. I
consider two alternatives to implement : using pair class or using a
separate class/struct containing two member strings. I prefer the
latter for it's more descriptive. However, in the latter
implementation (equivalent of which is shown below), I got some
compiler errors on gcc 3.3.1 with MyClass.
#include<map>
#include <string>
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |