Compare commits

...

18 Commits

Author SHA1 Message Date
002ec11425 This commit was manufactured by cvs2svn to create tag
'Version_1_20_2'.

[SVN r9073]
2001-02-10 14:52:07 +00:00
08a2ab3fe6 Always have a definition for each traits member, even if it can't be properly
deduced. These will be incomplete types in some cases (undefined<void>), but it
helps suppress MSVC errors elsewhere


[SVN r9064]
2001-02-10 00:05:17 +00:00
2947fb7051 Applied John Maddock's Borland patch Moving <true> specialization to unspecialized template
[SVN r9058]
2001-02-09 15:23:55 +00:00
cd1eecd245 Add parens to appease Borland
[SVN r9043]
2001-02-09 03:30:12 +00:00
9ac4d90d82 *** empty log message ***
[SVN r9029]
2001-02-08 04:44:19 +00:00
a7ae27dc5b Added support for more of the traits members where possible, making this useful
as a replacement for std::iterator_traits<T> when used as a default template
parameter.


[SVN r9002]
2001-02-07 16:43:57 +00:00
ddccb755f4 Removed useless #includes of standard library headers
[SVN r8993]
2001-02-07 04:52:58 +00:00
8ffb174556 Initial Checkin
[SVN r8992]
2001-02-07 04:51:12 +00:00
8b60ca8d0a Factored if_true out into boost/detail/select_type.hpp
[SVN r8991]
2001-02-07 04:49:32 +00:00
3cbecf5ddd fix bool logic bug introduced by Jeremy's compilation fixes
[SVN r8988]
2001-02-06 22:56:37 +00:00
82af891892 ported to KAI C++
[SVN r8955]
2001-02-06 01:21:11 +00:00
4bfd4da650 Fixed logic of difference_type selection, which was completely wack. In the
process, added digit_traits<> to compute the number of digits in intmax_t even
when not supplied by numeric_limits<>.


[SVN r8747]
2001-01-24 01:44:05 +00:00
37d08acea1 Initial checkin
[SVN r8702]
2001-01-22 04:08:29 +00:00
708fd64f4e tweak a comment
[SVN r8680]
2001-01-21 16:18:41 +00:00
5963c3d44d Initial checkin
[SVN r8664]
2001-01-21 05:18:41 +00:00
4d24f82e6e Initial Checkin
[SVN r8661]
2001-01-21 00:16:10 +00:00
de2904c9a1 ported the graph library to borland
[SVN r7965]
2000-10-17 00:16:05 +00:00
9b9d2241a7 removed tabs
[SVN r7835]
2000-09-25 21:19:29 +00:00
5 changed files with 535 additions and 2 deletions

View File

@ -0,0 +1,248 @@
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// Boost versions of
//
// std::iterator_traits<>::iterator_category
// std::iterator_traits<>::difference_type
// std::distance()
//
// ...for all compilers and iterators
//
// Additionally, if partial specialization is supported or X is not a pointer
// std::iterator_traits<X>::value_type
//
// And if partial specialization is supported or (X is not a pointer and the
// library isn't the VC6 standard library),
// std::iterator_traits<X>::pointer
// std::iterator_traits<X>::reference
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 09 Feb 2001 - Always have a definition for each traits member, even if it
// can't be properly deduced. These will be incomplete types in
// some cases (undefined<void>), but it helps suppress MSVC errors
// elsewhere (David Abrahams)
// 07 Feb 2001 - Support for more of the traits members where possible, making
// this useful as a replacement for std::iterator_traits<T> when
// used as a default template parameter.
// 06 Feb 2001 - Removed useless #includes of standard library headers
// (David Abrahams)
#ifndef ITERATOR_DWA122600_HPP_
# define ITERATOR_DWA122600_HPP_
# include <boost/config.hpp>
# include <boost/type_traits.hpp>
# include <iterator>
# include <cstddef>
// STLPort 4.0 and betas have a bug when debugging is enabled and there is no
// partial specialization: instead of an iterator_category typedef, the standard
// container iterators have _Iterator_category.
//
// Also, whether debugging is enabled or not, there is a broken specialization
// of std::iterator<output_iterator_tag,void,void,void,void> which has no
// typedefs but iterator_category.
# if defined(__SGI_STL_PORT) && (__SGI_STL_PORT <= 0x410) && !defined(__STL_CLASS_PARTIAL_SPECIALIZATION)
# ifdef __STL_DEBUG
# define BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
# endif
# define BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
# endif // STLPort <= 4.1b4 && no partial specialization
namespace boost { namespace detail {
# if !defined(BOOST_NO_STD_ITERATOR_TRAITS) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
using std::iterator_traits;
using std::distance;
# else
// Workarounds for less-capable implementations
template <bool is_ptr> struct iterator_traits_select;
template <class T> struct undefined;
template <> struct iterator_traits_select<true>
{
template <class Ptr>
struct traits
{
typedef std::ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;
#ifdef BOOST_MSVC
// Keeps MSVC happy under certain circumstances. It seems class template default
// arguments are partly instantiated even when not used when the class template
// is the return type of a function template.
typedef undefined<void> value_type;
typedef undefined<void> pointer;
typedef undefined<void> reference;
#endif
};
};
# ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
no_result bad_category_helper(...);
template <class C, class T> yes_result bad_category_helper(std::_DBG_iter<C,T>*);
template <bool has_bad_category_typedef> struct bad_category_select;
template <>
struct bad_category_select<true>
{
template <class Iterator>
struct category { typedef typename Iterator::_Iterator_category type; };
};
template <>
struct bad_category_select<false>
{
template <class Iterator>
struct category { typedef typename Iterator::iterator_category type; };
};
template <class Iterator>
struct iterator_category_select
{
private:
static Iterator p;
enum { has_bad_category
= sizeof(bad_category_helper(&p)) == sizeof(yes_result) };
typedef bad_category_select<has_bad_category> category_select;
public:
typedef typename category_select::template category<Iterator>::type type;
};
# endif
# ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
template <bool is_bad_output_iterator> struct bad_output_iterator_select;
template <>
struct bad_output_iterator_select<true>
{
template <class Iterator>
struct non_category_traits {
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
};
};
template <>
struct bad_output_iterator_select<false>
{
template <class Iterator>
struct non_category_traits {
typedef typename Iterator::value_type value_type;
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
};
};
# endif
template <> struct iterator_traits_select<false>
{
template <class Iterator>
struct traits
# if defined(BOOST_NO_STD_ITERATOR_TRAITS)
{
# if defined(BOOST_MSVC) && !defined(__SGI_STL_PORT)
typedef typename Iterator::distance_type difference_type;
typedef typename Iterator::value_type value_type;
#ifdef BOOST_MSVC // Keeps MSVC happy under certain circumstances
typedef undefined<void> pointer;
typedef undefined<void> reference;
#endif
# elif !defined(BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION)
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::value_type value_type;
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
# else
typedef bad_output_iterator_select<
is_convertible<const volatile Iterator*,
const volatile std::iterator<std::output_iterator_tag,void,void,void,void>*
>::value> non_category_traits_select;
typedef non_category_traits_select::template non_category_traits<Iterator> non_category_traits;
public:
typedef typename non_category_traits::value_type value_type;
typedef typename non_category_traits::difference_type difference_type;
typedef typename non_category_traits::pointer pointer;
typedef typename non_category_traits::reference reference;
# endif
# if !defined(BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF)
typedef typename Iterator::iterator_category iterator_category;
# else
typedef typename iterator_category_select<Iterator>::type iterator_category;
# endif
};
# else
{
typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
};
# endif
};
template <class Iterator>
struct iterator_traits
: iterator_traits_select<is_pointer<remove_cv<Iterator>::type>::value>::template traits<Iterator>
{
private:
typedef typename iterator_traits_select<
is_pointer<remove_cv<Iterator>::type>::value>::template traits<Iterator> traits;
public:
// Why do I need to define these typedefs? It keeps MSVC happy somehow.
// Why don't I need to define the other typedefs? Who knows?!?
typedef typename traits::difference_type difference_type;
typedef typename traits::iterator_category iterator_category;
};
template <class Category>
struct distance_select {
template <class Iterator>
static typename ::boost::detail::iterator_traits<Iterator>::difference_type
distance(Iterator i1, const Iterator i2)
{
typename ::boost::detail::iterator_traits<Iterator>::difference_type result = 0;
while (i1 != i2)
{
++i1;
++result;
}
return result;
}
};
template <>
struct distance_select<std::random_access_iterator_tag> {
template <class Iterator>
static typename ::boost::detail::iterator_traits<Iterator>::difference_type
distance(const Iterator i1, const Iterator i2)
{
return i2 - i1;
}
};
template <class Iterator>
inline typename ::boost::detail::iterator_traits<Iterator>::difference_type
distance(const Iterator& first, const Iterator& last)
{
typedef typename ::boost::detail::iterator_traits<Iterator>::iterator_category iterator_category;
return distance_select<iterator_category>::distance(first, last);
}
# endif // workarounds
}}
# undef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
# undef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
#endif // ITERATOR_DWA122600_HPP_

View File

@ -0,0 +1,196 @@
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
//
// Template class is_signed and its documentation is:
// (C) Copyright Howard Hinnant 2001. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
//
// Template class numeric_traits<Number> --
//
// Supplies:
//
// typedef difference_type -- a type used to represent the difference
// between any two values of Number.
//
// Support:
// 1. Not all specializations are supplied
//
// 2. Use of specializations that are not supplied will cause a
// compile-time error
//
// 3. Users are free to specialize numeric_traits for any type.
//
// 4. Right now, specializations are only supplied for integer types.
//
// 5. On implementations which do not supply compile-time constants in
// std::numeric_limits<>, only specializations for built-in integer types
// are supplied.
//
// 6. Handling of numbers whose range of representation is at least as
// great as boost::intmax_t can cause some differences to be
// unrepresentable in difference_type:
//
// Number difference_type
// ------ ---------------
// signed Number
// unsigned intmax_t
//
// template <class Number> typename numeric_traits<Number>::difference_type
// numeric_distance(Number x, Number y)
// computes (y - x), attempting to avoid overflows.
//
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 06 Feb 2001 - Factored if_true out into boost/detail/select_type.hpp
// (David Abrahams)
// 23 Jan 2001 - Fixed logic of difference_type selection, which was
// completely wack. In the process, added digit_traits<>
// to compute the number of digits in intmax_t even when
// not supplied by numeric_limits<>. (David Abrahams)
// 21 Jan 2001 - Created (David Abrahams)
#ifndef BOOST_NUMERIC_TRAITS_HPP_DWA20001901
# define BOOST_NUMERIC_TRAITS_HPP_DWA20001901
# include <boost/config.hpp>
# include <boost/cstdint.hpp>
# include <boost/static_assert.hpp>
# include <boost/type_traits.hpp>
# include <boost/detail/select_type.hpp>
# ifndef BOOST_NO_LIMITS
# include <limits>
# endif
namespace boost { namespace detail {
// Template class is_signed -- determine whether a numeric type is signed
// Requires that T is constructable from the literals -1 and 0. Compile-time
// error results if that requirement is not met (and thus signedness is not
// likely to have meaning for that type).
template <class Number>
struct is_signed
{
#if defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_MSVC)
enum { value = (Number(-1) < Number(0)) };
#else
enum { value = std::numeric_limits<Number>::is_signed };
#endif
};
# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
// digit_traits - compute the number of digits in a built-in integer
// type. Needed for implementations on which numeric_limits is not specialized
// for intmax_t (e.g. VC6).
template <bool is_specialized> struct digit_traits_select;
// numeric_limits is specialized; just select that version of digits
template <> struct digit_traits_select<true>
{
template <class T> struct traits
{
enum { digits = std::numeric_limits<T>::digits };
};
};
// numeric_limits is not specialized; compute digits from sizeof(T)
template <> struct digit_traits_select<false>
{
template <class T> struct traits
{
enum { digits = sizeof(T) * std::numeric_limits<unsigned char>::digits
- (is_signed<T>::value ? 1 : 0)
};
};
};
// here's the "usable" template
template <class T> struct digit_traits
{
enum {
digits = digit_traits_select<(
std::numeric_limits<T>::is_specialized
)>::template traits<T>::digits
};
};
#endif
// Template class integer_traits<Integer> -- traits of various integer types
// This should probably be rolled into boost::integer_traits one day, but I
// need it to work without <limits>
template <class Integer>
struct integer_traits
{
# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
private:
typedef Integer integer_type;
typedef std::numeric_limits<integer_type> x;
# ifdef BOOST_MSVC
// for some reason, MSVC asserts when it shouldn't unless we make these
// local definitions
enum {
is_integer = x::is_integer,
is_specialized = x::is_specialized
};
BOOST_STATIC_ASSERT(is_integer);
BOOST_STATIC_ASSERT(is_specialized);
# endif
public:
typedef typename
if_true<(int(x::is_signed)
&& (!int(x::is_bounded)
// digits is the number of no-sign bits
|| (int(x::digits) + 1 >= digit_traits<boost::intmax_t>::digits)))>::template then<
Integer,
typename if_true<(int(x::digits) + 1 < digit_traits<signed int>::digits)>::template then<
signed int,
typename if_true<(int(x::digits) + 1 < digit_traits<signed long>::digits)>::template then<
signed long,
// else
intmax_t
>::type>::type>::type difference_type;
# else
BOOST_STATIC_ASSERT(boost::is_integral<Integer>::value);
typedef typename
if_true<(sizeof(Integer) >= sizeof(intmax_t))>::template then<
typename if_true<(is_signed<Integer>::value)>::template then<
Integer,
intmax_t
>::type,
typename if_true<(sizeof(Integer) < sizeof(std::ptrdiff_t))>::template then<
std::ptrdiff_t,
intmax_t
>::type
>::type difference_type;
# endif
};
// Right now, only supports integers, but should be expanded.
template <class Number>
struct numeric_traits
{
typedef typename integer_traits<Number>::difference_type difference_type;
};
template <class Number>
typename numeric_traits<Number>::difference_type numeric_distance(Number x, Number y)
{
typedef typename numeric_traits<Number>::difference_type difference_type;
return difference_type(y) - difference_type(x);
}
}}
#endif // BOOST_NUMERIC_TRAITS_HPP_DWA20001901

View File

@ -0,0 +1,36 @@
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
//
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 09 Feb 01 Applied John Maddock's Borland patch Moving <true>
// specialization to unspecialized template (David Abrahams)
// 06 Feb 01 Created (David Abrahams)
#ifndef SELECT_TYPE_DWA20010206_HPP
# define SELECT_TYPE_DWA20010206_HPP
namespace boost { namespace detail {
// Template class if_true -- select among 2 types based on a bool constant expression
// Usage:
// typename if_true<(bool_const_expression)>::template then<true_type, false_type>::type
template <bool>
struct if_true
{
template <class T, class F>
struct then { typedef T type; };
};
template <>
struct if_true<false>
{
template <class T, class F>
struct then { typedef F type; };
};
}}
#endif // SELECT_TYPE_DWA20010206_HPP

View File

@ -12,15 +12,44 @@
#include <boost/config.hpp>
/*
There is a bug in the Borland compiler with regards to using
integers to specialize templates. This made it hard to use ct_if in
the graph library. Changing from 'ct_if' to 'ct_if_t' fixed the
problem.
*/
namespace boost {
struct ct_if_error { };
struct true_type { enum { value = true }; };
struct false_type { enum { value = false }; };
template <class A, class B>
struct ct_and { typedef false_type type; };
template <> struct ct_and<true_type,true_type> { typedef true_type type; };
template <class A> struct ct_not { typedef ct_if_error type; };
template <> struct ct_not<true_type> { typedef false_type type; };
template <> struct ct_not<false_type> { typedef true_type type; };
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <int cond, class A, class B>
struct ct_if { typedef A type; };
struct ct_if { typedef ct_if_error type; };
template <class A, class B>
struct ct_if<1, A, B> { typedef A type; };
template <class A, class B>
struct ct_if<0, A, B> { typedef B type; };
template <class cond, class A, class B>
struct ct_if_t { typedef ct_if_error type; };
template <class A, class B>
struct ct_if_t<true_type, A, B> { typedef A type; };
template <class A, class B>
struct ct_if_t<false_type, A, B> { typedef B type; };
#else
namespace detail {
@ -32,7 +61,7 @@ namespace boost {
struct SelectFirstType {
template<class A, class B>
struct Template { typedef A type; };
struct Template { typedef A type; };
};
struct SelectSecondType {
@ -59,6 +88,11 @@ namespace boost {
typedef typename Selector::template Template<A, B>::type type;
};
template <class cond, class A, class B>
struct ct_if_t {
typedef typename ct_if<cond::value, A, B>::type type;
};
#endif
} // namespace boost

19
include/boost/type.hpp Normal file
View File

@ -0,0 +1,19 @@
// (C) Copyright David Abrahams 2001. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_TYPE_DWA20010120_HPP
# define BOOST_TYPE_DWA20010120_HPP
namespace boost {
// Just a simple "type envelope". Useful in various contexts, mostly to work
// around some MSVC deficiencies.
template <class T>
struct type {};
}
#endif // BOOST_TYPE_DWA20010120_HPP