src/lemon/concept_check.h
author marci
Sat, 20 Nov 2004 14:23:27 +0000
changeset 1014 aae850a2394d
parent 986 e997802b855c
child 1022 567f392d1d2e
permissions -rw-r--r--
Modifications for hugo 0.2
klao@946
     1
// -*- C++ -*-
klao@946
     2
// Modified for use in LEMON.
klao@946
     3
// We should really consider using Boost...
klao@946
     4
klao@946
     5
klao@946
     6
//
klao@946
     7
// (C) Copyright Jeremy Siek 2000.
klao@946
     8
// Distributed under the Boost Software License, Version 1.0. (See
klao@946
     9
// accompanying file LICENSE_1_0.txt or copy at
klao@946
    10
// http://www.boost.org/LICENSE_1_0.txt)
klao@946
    11
//
klao@946
    12
// Revision History:
klao@946
    13
//   05 May   2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek)
klao@946
    14
//   02 April 2001: Removed limits header altogether. (Jeremy Siek)
klao@946
    15
//   01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock)
klao@946
    16
//
klao@946
    17
klao@946
    18
// See http://www.boost.org/libs/concept_check for documentation.
klao@946
    19
klao@946
    20
#ifndef LEMON_BOOST_CONCEPT_CHECKS_HPP
klao@946
    21
#define LEMON_BOOST_CONCEPT_CHECKS_HPP
klao@946
    22
klao@946
    23
namespace lemon {
klao@946
    24
klao@946
    25
  /*
klao@946
    26
    "inline" is used for ignore_unused_variable_warning()
klao@946
    27
    and function_requires() to make sure there is no
alpar@986
    28
    overtarget with g++.
klao@946
    29
  */
klao@946
    30
klao@946
    31
  template <class T> inline void ignore_unused_variable_warning(const T&) { }
klao@946
    32
klao@946
    33
  template <class Concept>
klao@946
    34
  inline void function_requires()
klao@946
    35
  {
klao@946
    36
#if !defined(NDEBUG)
klao@946
    37
    void (Concept::*x)() = & Concept::constraints;
klao@946
    38
    ignore_unused_variable_warning(x);
klao@946
    39
#endif
klao@946
    40
  }
klao@946
    41
deba@989
    42
  template <typename Concept, typename Type>
deba@989
    43
  inline void checkConcept() {
deba@989
    44
    function_requires<typename Concept::template Constraints<Type> >();
deba@989
    45
  }
deba@989
    46
klao@946
    47
#define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
klao@946
    48
  typedef void (ns::concept <type_var>::* func##type_var##concept)(); \
klao@946
    49
  template <func##type_var##concept Tp1_> \
klao@946
    50
  struct concept_checking_##type_var##concept { }; \
klao@946
    51
  typedef concept_checking_##type_var##concept< \
klao@946
    52
    BOOST_FPTR ns::concept<type_var>::constraints> \
klao@946
    53
    concept_checking_typedef_##type_var##concept
klao@946
    54
klao@946
    55
#define BOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \
klao@946
    56
  typedef void (ns::concept <type_var1,type_var2>::* \
klao@946
    57
     func##type_var1##type_var2##concept)(); \
klao@946
    58
  template <func##type_var1##type_var2##concept Tp1_> \
klao@946
    59
  struct concept_checking_##type_var1##type_var2##concept { }; \
klao@946
    60
  typedef concept_checking_##type_var1##type_var2##concept< \
klao@946
    61
    BOOST_FPTR ns::concept<type_var1,type_var2>::constraints> \
klao@946
    62
    concept_checking_typedef_##type_var1##type_var2##concept
klao@946
    63
klao@946
    64
#define BOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \
klao@946
    65
  typedef void (ns::concept <tv1,tv2,tv3>::* \
klao@946
    66
     func##tv1##tv2##tv3##concept)(); \
klao@946
    67
  template <func##tv1##tv2##tv3##concept Tp1_> \
klao@946
    68
  struct concept_checking_##tv1##tv2##tv3##concept { }; \
klao@946
    69
  typedef concept_checking_##tv1##tv2##tv3##concept< \
klao@946
    70
    BOOST_FPTR ns::concept<tv1,tv2,tv3>::constraints> \
klao@946
    71
    concept_checking_typedef_##tv1##tv2##tv3##concept
klao@946
    72
klao@946
    73
#define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
klao@946
    74
  typedef void (ns::concept <tv1,tv2,tv3,tv4>::* \
klao@946
    75
     func##tv1##tv2##tv3##tv4##concept)(); \
klao@946
    76
  template <func##tv1##tv2##tv3##tv4##concept Tp1_> \
klao@946
    77
  struct concept_checking_##tv1##tv2##tv3##tv4##concept { }; \
klao@946
    78
  typedef concept_checking_##tv1##tv2##tv3##tv4##concept< \
klao@946
    79
    BOOST_FPTR ns::concept<tv1,tv2,tv3,tv4>::constraints> \
klao@946
    80
    concept_checking_typedef_##tv1##tv2##tv3##tv4##concept
klao@946
    81
klao@946
    82
klao@946
    83
} // namespace lemon
klao@946
    84
klao@946
    85
#endif // LEMON_BOOST_CONCEPT_CHECKS_HPP