C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[stl] map avec clef "primitive"

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Bruno Causse
Guest





PostPosted: Wed Apr 11, 2007 9:42 pm    Post subject: [stl] map avec clef "primitive" Reply with quote



bonsoir,

je cherche a creer une map avec pour clef un entier.

est ce possible, ou bien la clef doit etre obligatoirement un objet?

map<int, objet>

merci

--
Bruno Causse
http://perso.wanadoo.fr/othello
Back to top
Fabien LE LEZ
Guest





PostPosted: Wed Apr 11, 2007 9:53 pm    Post subject: Re: [stl] map avec clef "primitive" Reply with quote



On Wed, 11 Apr 2007 18:42:57 +0200, Bruno Causse :

Quote:
je cherche a creer une map avec pour clef un entier.

est ce possible,

Oui.

Quote:
ou bien la clef doit etre obligatoirement un objet?

Non.

Note que si un entier n'est pas un objet à part entière, tout est fait
pour qu'il se comporte, dans le plus de cas possible, comme un objet
(à sémantique de valeur). Ou plutôt, tout est fait pour qu'un objet se
comporte, autant que possible, comme un entier.
Back to top
James Kanze
Guest





PostPosted: Thu Apr 12, 2007 9:12 am    Post subject: Re: map avec clef "primitive" Reply with quote



On Apr 11, 6:42 pm, pasde.hcyrano.s...@free.fr (Bruno Causse) wrote:

Quote:
je cherche a creer une map avec pour clef un entier.

est ce possible, ou bien la clef doit etre obligatoirement un objet?

map<int, objet

Il suffit soit que l'opérateur < (std::less, en fait) soit
défini pour le type, soit que tu fournis un troisième paramètre
pour le template, un type qu'on peut utiliser comme une
fonction, et qui établit une rélation d'ordre sur le type de la
clé. Des types arithmétique, donc, vont très bien (puisque '<'
est défini sur eux), tout pointeur aussi (parce que std::less
est garanti de marcher, même si ce n'est pas le cas de '<').

--
James Kanze (GABI Software) email:james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.