boost::is_const does not recognize constant type

Hi, The following type expression evaluates to the false_ type: boost::is_const<std::map<std::string,std::string>::const_iterator::refer ence>::type It should evaluate to the true type because ...::reference is const std::pair<const std::string,std::string> Does anybody know the reason why? I compile this using MSVC 2005 (SP1). Regards, Jochen Becher Jochen Becher Software Architect Stryker Navigation Stryker Leibinger GmbH & Co. KG Boetzinger Strasse 41 79111 Freiburg, Germany t: +49 761 4512 463 f:: +49 761 4512 449 463 jochen.becher@stryker.com Stryker Leibinger GmbH & Co. KG Sitz: Freiburg - Handelsregister: AG Freiburg HRA 4375 Komplementaerin: Stryker Beteiligungs GmbH Geschaeftsfuehrer: Dr. Heinrich W. Dreyer, Klaus Welte Sitz: Freiburg - Handelsregister: AG Freiburg HRB 5441 Bankverbindung: Bank of America N.A. Frankfurt 17 362 010 - BLZ 500 109 00, IBAN: DE04 5001 0900 0017 3620 10 Diese Nachricht und etwaige Dateianhaenge sind vertrauliche Informationen, die besonderen Geheimhaltungsvereinbarungen oder -vorschriften unterliegen koennen. Falls Sie nicht der beabsichtigte Empfaenger der Nachricht sind, werden Sie gebeten, den Absender telefonisch oder durch E-Mail zu unterrichten und die Nachricht und etwaige Dateianhaenge vollstaendig und endgueltig zu loeschen. Die Nachricht und ihr Inhalt duerfen in diesem Fall nicht kopiert, ausgedruckt oder weitergeleitet werden. This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not the intended recipient, please telephone or e-mail the sender and delete this message and any attachment from your system. If you are not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.

Becher, Jochen wrote:
The following type expression evaluates to the false_ type:
boost::is_const<std::map<std::string,std::string>::const_iterator::refer ence>::type
It should evaluate to the true type because ...::reference is
const std::pair<const std::string,std::string>
Nope, wouldn't that be: const std::pair<const std::string,std::string>& which is a reference type and can be neither const nor volatile qualified (the const qualifier in the above refers to the thing being referenced not the reference itself). If you feed it through remove_reference before passing to is_const then you should get true as the result. HTH, John.

Hi John, thank you, you are right, remove_reference fixes the problem. I do not understand why MSVC print the reference type without the reference symbol (I checked this twice) but internally it seems to be a reference type (and that is what you expect for typedef ...::reference). My final code is this: template<class ITERATOR> class SecondIterator_TC : public boost::iterator_adaptor< SecondIterator_TC<ITERATOR>, ITERATOR, typename ITERATOR::value_type::second_type, boost::use_default, typename boost::mpl::eval_if< typename boost::is_const<typename boost::remove_reference< typename ITERATOR::reference>::type>::type, boost::mpl::identity<typename ITERATOR::value_type::second_type const&>, boost::mpl::identity<typename ITERATOR::value_type::second_type &>
::type, boost::use_default> { ... };
It is my first attempt to use iterator_adaptor. It allows iterators over maps (and other iterators that dereference to a pair) to use like iterators on most other containers. The Reference template parameter now looks really complex, is there any simpler solution? Regards, Jochen -----Urspruengliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von John Maddock Gesendet: Mittwoch, 28. Mai 2008 16:39 An: boost-users@lists.boost.org Betreff: Re: [Boost-users] boost::is_const does not recognize constant type Becher, Jochen wrote:
The following type expression evaluates to the false_ type:
boost::is_const<std::map<std::string,std::string>::const_iterator::refer ence>::type
It should evaluate to the true type because ...::reference is
const std::pair<const std::string,std::string>
Nope, wouldn't that be: const std::pair<const std::string,std::string>& which is a reference type and can be neither const nor volatile qualified (the const qualifier in the above refers to the thing being referenced not the reference itself). If you feed it through remove_reference before passing to is_const then you should get true as the result. HTH, John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users Stryker Leibinger GmbH & Co. KG Sitz: Freiburg - Handelsregister: AG Freiburg HRA 4375 Komplementaerin: Stryker Beteiligungs GmbH Geschaeftsfuehrer: Dr. Heinrich W. Dreyer, Klaus Welte Sitz: Freiburg - Handelsregister: AG Freiburg HRB 5441 Bankverbindung: Bank of America N.A. Frankfurt 17 362 010 - BLZ 500 109 00, IBAN: DE04 5001 0900 0017 3620 10 Diese Nachricht und etwaige Dateianhaenge sind vertrauliche Informationen, die besonderen Geheimhaltungsvereinbarungen oder -vorschriften unterliegen koennen. Falls Sie nicht der beabsichtigte Empfaenger der Nachricht sind, werden Sie gebeten, den Absender telefonisch oder durch E-Mail zu unterrichten und die Nachricht und etwaige Dateianhaenge vollstaendig und endgueltig zu loeschen. Die Nachricht und ihr Inhalt duerfen in diesem Fall nicht kopiert, ausgedruckt oder weitergeleitet werden. This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not the intended recipient, please telephone or e-mail the sender and delete this message and any attachment from your system. If you are not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.

Becher, Jochen wrote:
thank you, you are right, remove_reference fixes the problem. I do not understand why MSVC print the reference type without the reference symbol (I checked this twice) but internally it seems to be a reference type (and that is what you expect for typedef ...::reference).
I don't know, what you mean with "MSVC print the reference type". Do you mean the debugger view, the result of typeid(your_type).name()? The standard clearly says that typeid(some_type) == typeid(some_type&), see [expr.typeid]/4: "[..] If the type of the type-id is a reference type, the result of the typeid expression refers to a type_info object representing the referenced type [..] " So, it's more than reasonable that any debugger view will use a similar logic.
It should evaluate to the true type because ...::reference is
const std::pair<const std::string,std::string>
Nope, wouldn't that be:
const std::pair<const std::string,std::string>&
which is a reference type and can be neither const nor volatile qualified (the const qualifier in the above refers to the thing being referenced not the reference itself). If you feed it through remove_reference before passing to is_const then you should get true as the result.
IMO John meant the reference type, otherwise his message would not make much sense. Greetings from Bremen, Daniel Krügler

Because I didn't understand the problem MSVC had with my source I wrote a little template: template<typename T> struct dump_type { dump_type() { type_dumped; } }; It does nothing then creating an error message (identifier type_dumped not defined). The error message contains type T also. I used this to see how some type are defined. Using it with dump_type<std::map<std::string,std:string>::const_iterator::reference> x; prints: T=const std::pair<const std::string,std::string> There is no reference symbol in this dumped type expression. Because of that I simply didn't recognize that ::reference is a reference type. Regards, Jochen -----Urspruengliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Daniel Kruegler Gesendet: Donnerstag, 29. Mai 2008 08:20 An: boost-users@lists.boost.org Betreff: Re: [Boost-users] boost::is_const does not recognize constant type Becher, Jochen wrote:
thank you, you are right, remove_reference fixes the problem. I do not understand why MSVC print the reference type without the reference symbol (I checked this twice) but internally it seems to be a reference type (and that is what you expect for typedef ...::reference).
I don't know, what you mean with "MSVC print the reference type". Do you mean the debugger view, the result of typeid(your_type).name()? The standard clearly says that typeid(some_type) == typeid(some_type&), see [expr.typeid]/4: "[..] If the type of the type-id is a reference type, the result of the typeid expression refers to a type_info object representing the referenced type [..] " So, it's more than reasonable that any debugger view will use a similar logic.
It should evaluate to the true type because ...::reference is
const std::pair<const std::string,std::string>
Nope, wouldn't that be:
const std::pair<const std::string,std::string>&
which is a reference type and can be neither const nor volatile qualified (the const qualifier in the above refers to the thing being referenced not the reference itself). If you feed it through remove_reference before passing to is_const then you should get true as the result.
IMO John meant the reference type, otherwise his message would not make much sense. Greetings from Bremen, Daniel Kruegler _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users Stryker Leibinger GmbH & Co. KG Sitz: Freiburg - Handelsregister: AG Freiburg HRA 4375 Komplementaerin: Stryker Beteiligungs GmbH Geschaeftsfuehrer: Dr. Heinrich W. Dreyer, Klaus Welte Sitz: Freiburg - Handelsregister: AG Freiburg HRB 5441 Bankverbindung: Bank of America N.A. Frankfurt 17 362 010 - BLZ 500 109 00, IBAN: DE04 5001 0900 0017 3620 10 Diese Nachricht und etwaige Dateianhaenge sind vertrauliche Informationen, die besonderen Geheimhaltungsvereinbarungen oder -vorschriften unterliegen koennen. Falls Sie nicht der beabsichtigte Empfaenger der Nachricht sind, werden Sie gebeten, den Absender telefonisch oder durch E-Mail zu unterrichten und die Nachricht und etwaige Dateianhaenge vollstaendig und endgueltig zu loeschen. Die Nachricht und ihr Inhalt duerfen in diesem Fall nicht kopiert, ausgedruckt oder weitergeleitet werden. This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not the intended recipient, please telephone or e-mail the sender and delete this message and any attachment from your system. If you are not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.
participants (3)
-
Becher, Jochen
-
Daniel Krügler
-
John Maddock