Boost logo

Boost Users :

Subject: [Boost-users] [utility] BOOST_IDENTITY_TYPE drops const-ness of value types
From: Nick Stokes (randomaccessiterator_at_[hidden])
Date: 2016-04-29 11:30:13


Looks like const value types, once passed thru BOOST_IDENTITY_TYPE,
"becomes" non-const. Like so:

// Attempt to implement a multi-argument utility macro, where arguments are
// types, parenthesized only when required (by the user, when type has
commas)
#define ASSERT_EQUAL( t1, t2 ) \
   static_assert( std::is_same< \
     BOOST_IDENTITY_TYPE((t1)), BOOST_IDENTITY_TYPE((t2)) \
>::value, #t1 " not same as " #t2)

// sanity check: static_asserts as expected
ASSERT_EQUAL( int, double );

// sanity check: static_assert as expected for types with commas
ASSERT_EQUAL( (std::pair<int, double>), (std::pair<double, int>) );

// Here is the failure: this is expected to assert but it doesnt!
ASSERT_EQUAL( const int, int );

>From the implementation of BOOST_IDENTITY_TYPE, it is clear why this is
happening, as the function signature is independent of const-ness of value
type.

Is this a bug? Or is this not the way BOOST_IDENTITY_TYPE is supposed to
be used?

Nick



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net