Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-02-23 15:58:13


I've just fixed is_array for compilers not supporting partial specialization
such that it no longer reports true for types with conversion operators that
convert to pointer types. Patches:

Index: composite_traits.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/type_traits/composite_traits.hpp,v
retrieving revision 1.15
diff -c -r1.15 composite_traits.hpp
*** composite_traits.hpp 2 Feb 2002 23:23:42 -0000 1.15
--- composite_traits.hpp 23 Feb 2002 20:51:22 -0000
***************
*** 141,160 ****
  ::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3,
A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19,
A20, A21, A22, A23, A24, A25, A26, A27, A28, A29));

- yes_type is_array_helper(const volatile void*, const volatile void*);
     template <class T>
! no_type is_array_helper(T*const volatile*, const volatile void*);
     no_type BOOST_TT_DECL is_array_helper(...);
  } // namespace detail
  template <typename T>
  struct is_array

  private:
! static T t;
  public:
     BOOST_STATIC_CONSTANT(bool, value =
        (::boost::type_traits::ice_and<
! (1 == sizeof(detail::is_array_helper(&t, t))),
           ::boost::type_traits::ice_not<

::boost::detail::is_reference_or_const_volatile<T>::value>::value,
           ::boost::type_traits::ice_not<
--- 141,161 ----
  ::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3,
A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19,
A20, A21, A22, A23, A24, A25, A26, A27, A28, A29));

     template <class T>
! yes_type is_array_helper(const volatile void*, const volatile void*,
void (*)(T x[]));
! template <class T>
! no_type is_array_helper(T*const volatile*, const volatile void*, void
(*)(T x[]));
     no_type BOOST_TT_DECL is_array_helper(...);
  } // namespace detail
  template <typename T>
  struct is_array

  private:
! static T t;
  public:
     BOOST_STATIC_CONSTANT(bool, value =
        (::boost::type_traits::ice_and<
! (1 == sizeof(detail::is_array_helper(&t, t, (void(*)(T))0))),
           ::boost::type_traits::ice_not<

::boost::detail::is_reference_or_const_volatile<T>::value>::value,
           ::boost::type_traits::ice_not<

Index: composite_traits_test.cpp
===================================================================
RCS file:
/cvsroot/boost/boost/libs/type_traits/tests/composite_traits_test.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -c -r1.9 -r1.10
*** composite_traits_test.cpp 7 Jan 2002 12:58:57 -0000 1.9
--- composite_traits_test.cpp 23 Feb 2002 20:49:05 -0000 1.10
***************
*** 17,22 ****
--- 17,27 ----
  NESTED_DECL(is_pointer)
  NESTED_DECL(is_reference)

+ struct convertible_to_pointer
+ {
+ operator char*() const;
+ };
+
  int cpp_main(int argc, char* argv[])
  {
     NESTED_TEST(is_array, int)
***************
*** 48,53 ****
--- 53,59 ----
  #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
     value_test(false, boost::is_array<test_abc1>::value)
  #endif
+ value_test(false, boost::is_array<convertible_to_pointer>::value)

     value_test(false, boost::is_pointer<int>::value)
     value_test(false, boost::is_pointer<int&>::value)
***************
*** 147,153 ****
  #elif defined(__GNUC__)
  unsigned int expected_failures = 1; // can't handle cv-qualified
references
  #elif defined(BOOST_MSVC)
! unsigned int expected_failures = 1;
  #elif defined(__MWERKS__) || defined(__HP_aCC)
  unsigned int expected_failures = 1; // is_enum doesn't work
  #else
--- 153,159 ----
  #elif defined(__GNUC__)
  unsigned int expected_failures = 1; // can't handle cv-qualified
references
  #elif defined(BOOST_MSVC)
! unsigned int expected_failures = 0;
  #elif defined(__MWERKS__) || defined(__HP_aCC)
  unsigned int expected_failures = 1; // is_enum doesn't work
  #else

+---------------------------------------------------------------+
                  David Abrahams
      C++ Booster (http://www.boost.org) O__ ==
      Pythonista (http://www.python.org) c/ /'_ ==
  resume: http://users.rcn.com/abrahams/resume.html (*) \(*) ==
          email: david.abrahams_at_[hidden]
+---------------------------------------------------------------+


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk