lemon/concept_check.h
author alpar
Fri, 04 Nov 2005 16:35:18 +0000
changeset 1773 ea5927cef15c
parent 1022 567f392d1d2e
child 1956 a055123339d5
permissions -rw-r--r--
Bugfix
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() {
klao@1022
    44
#if !defined(NDEBUG)
klao@1022
    45
    typedef typename Concept::template Constraints<Type> ConceptCheck;
klao@1022
    46
    void (ConceptCheck::*x)() = & ConceptCheck::constraints;
klao@1022
    47
    ignore_unused_variable_warning(x);
klao@1022
    48
#endif
deba@989
    49
  }
deba@989
    50
klao@946
    51
#define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
klao@946
    52
  typedef void (ns::concept <type_var>::* func##type_var##concept)(); \
klao@946
    53
  template <func##type_var##concept Tp1_> \
klao@946
    54
  struct concept_checking_##type_var##concept { }; \
klao@946
    55
  typedef concept_checking_##type_var##concept< \
klao@946
    56
    BOOST_FPTR ns::concept<type_var>::constraints> \
klao@946
    57
    concept_checking_typedef_##type_var##concept
klao@946
    58
klao@946
    59
#define BOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \
klao@946
    60
  typedef void (ns::concept <type_var1,type_var2>::* \
klao@946
    61
     func##type_var1##type_var2##concept)(); \
klao@946
    62
  template <func##type_var1##type_var2##concept Tp1_> \
klao@946
    63
  struct concept_checking_##type_var1##type_var2##concept { }; \
klao@946
    64
  typedef concept_checking_##type_var1##type_var2##concept< \
klao@946
    65
    BOOST_FPTR ns::concept<type_var1,type_var2>::constraints> \
klao@946
    66
    concept_checking_typedef_##type_var1##type_var2##concept
klao@946
    67
klao@946
    68
#define BOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \
klao@946
    69
  typedef void (ns::concept <tv1,tv2,tv3>::* \
klao@946
    70
     func##tv1##tv2##tv3##concept)(); \
klao@946
    71
  template <func##tv1##tv2##tv3##concept Tp1_> \
klao@946
    72
  struct concept_checking_##tv1##tv2##tv3##concept { }; \
klao@946
    73
  typedef concept_checking_##tv1##tv2##tv3##concept< \
klao@946
    74
    BOOST_FPTR ns::concept<tv1,tv2,tv3>::constraints> \
klao@946
    75
    concept_checking_typedef_##tv1##tv2##tv3##concept
klao@946
    76
klao@946
    77
#define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
klao@946
    78
  typedef void (ns::concept <tv1,tv2,tv3,tv4>::* \
klao@946
    79
     func##tv1##tv2##tv3##tv4##concept)(); \
klao@946
    80
  template <func##tv1##tv2##tv3##tv4##concept Tp1_> \
klao@946
    81
  struct concept_checking_##tv1##tv2##tv3##tv4##concept { }; \
klao@946
    82
  typedef concept_checking_##tv1##tv2##tv3##tv4##concept< \
klao@946
    83
    BOOST_FPTR ns::concept<tv1,tv2,tv3,tv4>::constraints> \
klao@946
    84
    concept_checking_typedef_##tv1##tv2##tv3##tv4##concept
klao@946
    85
klao@946
    86
klao@946
    87
} // namespace lemon
klao@946
    88
klao@946
    89
#endif // LEMON_BOOST_CONCEPT_CHECKS_HPP