fixed Assignable in concept_checks.hpp and changed the name of

concept_skeletons to concept_archetypes. Made lots of additions/changed
in concept_archetypes.


[SVN r8061]
This commit is contained in:
Jeremy Siek
2000-10-29 20:37:49 +00:00
parent f06d9504c7
commit 72f2233aa3
2 changed files with 315 additions and 30 deletions

View File

@@ -0,0 +1,278 @@
// $COPYRIGHT
#ifndef BOOST_CONCEPT_ARCHETYPES_HPP
#define BOOST_CONCEPT_ARCHETYPES_HPP
#include <iterator>
namespace boost {
//===========================================================================
// Basic Archetype Classes
class dummy_constructor { };
static dummy_constructor dummy_cons;
// A type that models no concept.
class null_archetype {
private:
null_archetype() { }
null_archetype(const null_archetype&) { }
null_archetype& operator=(const null_archetype&) { return *this; }
public:
null_archetype(dummy_constructor) { }
friend void dummy_friend(); // just to avoid warnings
};
template <class T>
class static_object {
public:
static T& get() {
dummy_constructor d;
static T x(d);
return x;
}
};
template <>
class static_object<bool> {
public:
static bool& get() {
static bool b;
return b;
}
};
template <class T, class Base = null_archetype>
class left_equality_comparable_archetype : public Base {
public:
left_equality_comparable_archetype(dummy_constructor x)
: Base(x) { }
};
template <class T>
bool operator==(const T&, const left_equality_comparable_archetype<T>&)
{ return true; }
template <class T>
bool operator!=(const T&, const left_equality_comparable_archetype<T>&)
{ return true; }
template <class Base = null_archetype>
class equality_comparable_archetype : public Base {
public:
equality_comparable_archetype(dummy_constructor x) : Base(x) { }
};
template <class Base>
bool operator==(const equality_comparable_archetype<Base>&,
const equality_comparable_archetype<Base>&) { return true; }
template <class Base>
bool operator!=(const equality_comparable_archetype<Base>&,
const equality_comparable_archetype<Base>&) { return true; }
template <class T, class Base = null_archetype>
class convertible_to : public Base {
public:
convertible_to(dummy_constructor x) : Base(x) { }
operator const T&() const { return static_object<T>::get(); }
};
template <class Base = null_archetype>
class default_constructible_archetype : public Base {
public:
default_constructible_archetype() : Base(dummy_cons) { }
default_constructible_archetype(dummy_constructor x) : Base(x) { }
};
template <class Base = null_archetype>
class copy_constructible_archetype : public Base {
public:
copy_constructible_archetype() : Base(dummy_cons) { }
copy_constructible_archetype(const copy_constructible_archetype&)
: Base(dummy_cons) { }
copy_constructible_archetype(dummy_constructor x) : Base(x) { }
};
template <class Base = null_archetype>
class assignable_archetype : public Base {
public:
assignable_archetype& operator=(const assignable_archetype&) {
return *this;
}
assignable_archetype(dummy_constructor x) : Base(x) { }
};
//===========================================================================
// Function Object Archetype Classes
template <class Arg, class Return>
class unary_function_archetype {
public:
const Return& operator()(const Arg&) {
return static_object<Return>::get();
}
};
template <class Arg>
class predicate_archetype {
typedef convertible_to<bool> Return;
public:
const Return& operator()(const Arg&) {
return static_object<Return>::get();
}
};
template <class Arg1, class Arg2>
class binary_predicate_archetype {
typedef convertible_to<bool> Return;
public:
const Return& operator()(const Arg1&, const Arg2&) {
return static_object<Return>::get();
}
};
//===========================================================================
// Iterator Archetype Classes
template <class T>
struct input_proxy {
operator const T&() { return static_object<T>::get(); }
};
template <class T>
class trivial_iterator_archetype
{
typedef trivial_iterator_archetype self;
public:
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
typedef T value_type;
typedef void reference;
typedef void pointer;
typedef void difference_type;
typedef void iterator_category;
#endif
trivial_iterator_archetype() { }
self& operator=(const self&) { return *this; }
bool operator==(const self&) const { return true; }
bool operator!=(const self&) const { return true; }
input_proxy<T> operator*() { return input_proxy<T>(); }
};
} // namespace boost
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace std {
template <class T>
struct iterator_traits< boost::trivial_iterator_archetype<T> >
{
typedef T value_type;
};
}
#endif
namespace boost {
template <class T>
struct input_output_proxy {
input_output_proxy<T>& operator=(const T&) { return *this; }
operator T() { return t; }
T t;
};
template <class T>
class mutable_trivial_iterator_archetype
{
typedef mutable_trivial_iterator_archetype self;
public:
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
typedef T value_type;
typedef void reference;
typedef void pointer;
typedef void difference_type;
typedef void iterator_category;
#endif
mutable_trivial_iterator_archetype() { }
self& operator=(const self&) { return *this; }
bool operator==(const self&) const { return true; }
bool operator!=(const self&) const { return true; }
input_output_proxy<T> operator*() { return input_output_proxy<T>(); }
T x;
};
} // namespace boost
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace std {
template <class T>
struct iterator_traits< boost::mutable_trivial_iterator_archetype<T> >
{
typedef T value_type;
};
}
#endif
namespace boost {
template <class T>
class input_iterator_archetype
{
public:
typedef input_iterator_archetype self;
public:
typedef std::input_iterator_tag iterator_category;
typedef T value_type;
typedef const T& reference;
typedef const T* pointer;
typedef std::ptrdiff_t difference_type;
input_iterator_archetype() { }
self& operator=(const self&) { return *this; }
bool operator==(const self&) const { return true; }
bool operator!=(const self&) const { return true; }
reference operator*() { return static_object<T>::get(); }
self& operator++() { return *this; }
self operator++(int) { return *this; }
};
struct output_proxy {
template <class T>
output_proxy& operator=(const T&) { return *this; }
};
class output_iterator_archetype
{
public:
typedef output_iterator_archetype self;
public:
typedef std::output_iterator_tag iterator_category;
typedef output_proxy value_type;
typedef output_proxy reference;
typedef void pointer;
typedef void difference_type;
output_iterator_archetype() { }
self& operator=(const self&) { return *this; }
bool operator==(const self&) const { return true; }
bool operator!=(const self&) const { return true; }
reference operator*() { return output_proxy(); }
self& operator++() { return *this; }
self operator++(int) { return *this; }
};
template <class T>
class forward_iterator_archetype
{
public:
typedef forward_iterator_archetype self;
public:
typedef std::forward_iterator_tag iterator_category;
typedef T value_type;
typedef T& reference;
typedef T* pointer;
typedef void difference_type;
forward_iterator_archetype() { }
self& operator=(const self&) { return *this; }
bool operator==(const self&) const { return true; }
bool operator!=(const self&) const { return true; }
reference operator*() { return static_object<T>::get(); }
self& operator++() { return *this; }
self operator++(int) { return *this; }
};
} // namespace boost
#endif // BOOST_CONCEPT_ARCHETYPES_H

View File

@@ -1,28 +1,9 @@
// //
//======================================================================= // (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame. // sell and distribute this software is granted provided this
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek // copyright notice appears in all copies. This software is provided
// // "as is" without express or implied warranty, and with no claim as
// This file is part of the Generic Graph Component Library // to its suitability for any purpose.
//
// You should have received a copy of the License Agreement for the
// Generic Graph Component Library along with the software; see the
// file LICENSE. If not, contact Office of Research, University of Notre
// Dame, Notre Dame, IN 46556.
//
// Permission to modify the code and to distribute modified code is
// granted, provided the text of this NOTICE is retained, a notice that
// the code was modified is included with the above COPYRIGHT NOTICE and
// with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
// file is distributed with the modified code.
//
// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
// By way of example, but not limitation, Licensor MAKES NO
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
// OR OTHER RIGHTS.
//=======================================================================
// //
#ifndef BOOST_GRAPH_DETAIL_CONCEPT_CHECKS_HPP #ifndef BOOST_GRAPH_DETAIL_CONCEPT_CHECKS_HPP
#define BOOST_GRAPH_DETAIL_CONCEPT_CHECKS_HPP #define BOOST_GRAPH_DETAIL_CONCEPT_CHECKS_HPP
@@ -119,7 +100,7 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
struct Integer_concept { struct Integer_concept {
void constraints() { void constraints() {
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
error_the_type_must_be_an_integer_type(); error__type_must_be_an_integer_type();
#endif #endif
} }
}; };
@@ -133,6 +114,21 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
// etc. // etc.
#endif #endif
template <class T>
struct SignedInteger_concept {
void constraints() {
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
error__type_must_be_a_signed_integer_type();
#endif
}
};
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <> struct SignedInteger_concept<short> { void constraints() {} };
template <> struct SignedInteger_concept<int> { void constraints() {} };
template <> struct SignedInteger_concept<long> { void constraints() {} };
// etc.
#endif
//=========================================================================== //===========================================================================
// Basic Concepts // Basic Concepts
@@ -146,6 +142,9 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
X x; X x;
}; };
// Issue, the SGI STL version of Assignable is
// different from the C++ standard definition of Assignable.
// This follows the C++ standard version.
template <class TT> template <class TT>
struct Assignable_concept struct Assignable_concept
{ {
@@ -153,16 +152,12 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL #if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
a = a; // require assignment operator a = a; // require assignment operator
#endif #endif
TT c(a); // require copy constructor
const_constraints(a); const_constraints(a);
ignore_unused_variable_warning(c);
} }
void const_constraints(const TT& b) { void const_constraints(const TT& b) {
#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL #if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
a = b; // const required for argument to assignment a = b; // const required for argument to assignment
#endif #endif
TT c(b); // const required for argument to copy constructor
ignore_unused_variable_warning(c);
} }
TT a; TT a;
}; };
@@ -213,7 +208,18 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
// the error message appears. // the error message appears.
template <class B> void require_boolean_return(B) { REQUIRE(B, Boolean); } template <class B> void require_boolean_return(B) { REQUIRE(B, Boolean); }
TT a, b; TT a, b;
bool r; };
template <class XX, class YY>
struct LeftEqualityComparable_concept
{
void constraints() {
require_boolean_return(b == a);
require_boolean_return(b != a);
}
template <class B> void require_boolean_return(B) { REQUIRE(B, Boolean); }
XX a;
YY b;
}; };
template <class TT> template <class TT>
@@ -267,6 +273,7 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
// require iterator_traits typedef's // require iterator_traits typedef's
#ifndef BOOST_NO_STD_ITERATOR_TRAITS #ifndef BOOST_NO_STD_ITERATOR_TRAITS
typedef typename std::iterator_traits<TT>::difference_type D; typedef typename std::iterator_traits<TT>::difference_type D;
REQUIRE(D, SignedInteger);
typedef typename std::iterator_traits<TT>::reference R; typedef typename std::iterator_traits<TT>::reference R;
typedef typename std::iterator_traits<TT>::pointer P; typedef typename std::iterator_traits<TT>::pointer P;
typedef typename std::iterator_traits<TT>::iterator_category C; typedef typename std::iterator_traits<TT>::iterator_category C;