lemon/concept_check.h
author Alpar Juttner <alpar@cs.elte.hu>
Fri, 04 Jan 2008 21:42:16 +0100
changeset 31 742abd64255e
parent 26 61bf7f22a6d6
child 39 0a01d811071f
permissions -rw-r--r--
Merge
alpar@25
     1
/* -*- C++ -*-
alpar@25
     2
 *
alpar@25
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@25
     4
 *
alpar@25
     5
 * Copyright (C) 2003-2007
alpar@25
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@25
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@25
     8
 *
alpar@25
     9
 * Permission to use, modify and distribute this software is granted
alpar@25
    10
 * provided that this copyright notice appears in all copies. For
alpar@25
    11
 * precise terms see the accompanying LICENSE file.
alpar@25
    12
 *
alpar@25
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@25
    14
 * express or implied, and with no claim as to its suitability for any
alpar@25
    15
 * purpose.
alpar@25
    16
 *
alpar@25
    17
 */
alpar@25
    18
alpar@26
    19
// This file contains a modified version of the concept checking
alpar@26
    20
// utility from BOOST.
alpar@26
    21
// See the appropriate copyright notice below.
alpar@25
    22
alpar@25
    23
// (C) Copyright Jeremy Siek 2000.
alpar@25
    24
// Distributed under the Boost Software License, Version 1.0. (See
alpar@25
    25
// accompanying file LICENSE_1_0.txt or copy at
alpar@25
    26
// http://www.boost.org/LICENSE_1_0.txt)
alpar@25
    27
//
alpar@25
    28
// Revision History:
alpar@25
    29
//   05 May   2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek)
alpar@25
    30
//   02 April 2001: Removed limits header altogether. (Jeremy Siek)
alpar@25
    31
//   01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock)
alpar@25
    32
//
alpar@25
    33
alpar@25
    34
// See http://www.boost.org/libs/concept_check for documentation.
alpar@25
    35
kpeter@27
    36
#ifndef LEMON_CONCEPT_CHECKS_H
kpeter@27
    37
#define LEMON_CONCEPT_CHECKS_H
alpar@25
    38
alpar@25
    39
namespace lemon {
alpar@25
    40
alpar@25
    41
  /*
alpar@25
    42
    "inline" is used for ignore_unused_variable_warning()
alpar@25
    43
    and function_requires() to make sure there is no
alpar@25
    44
    overtarget with g++.
alpar@25
    45
  */
alpar@25
    46
alpar@25
    47
  template <class T> inline void ignore_unused_variable_warning(const T&) { }
alpar@25
    48
alpar@25
    49
  template <class Concept>
alpar@25
    50
  inline void function_requires()
alpar@25
    51
  {
alpar@25
    52
#if !defined(NDEBUG)
alpar@25
    53
    void (Concept::*x)() = & Concept::constraints;
alpar@25
    54
    ignore_unused_variable_warning(x);
alpar@25
    55
#endif
alpar@25
    56
  }
alpar@25
    57
alpar@25
    58
  template <typename Concept, typename Type>
alpar@25
    59
  inline void checkConcept() {
alpar@25
    60
#if !defined(NDEBUG)
alpar@25
    61
    typedef typename Concept::template Constraints<Type> ConceptCheck;
alpar@25
    62
    void (ConceptCheck::*x)() = & ConceptCheck::constraints;
alpar@25
    63
    ignore_unused_variable_warning(x);
alpar@25
    64
#endif
alpar@25
    65
  }
alpar@25
    66
alpar@25
    67
#define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
alpar@25
    68
  typedef void (ns::concept <type_var>::* func##type_var##concept)(); \
alpar@25
    69
  template <func##type_var##concept Tp1_> \
alpar@25
    70
  struct concept_checking_##type_var##concept { }; \
alpar@25
    71
  typedef concept_checking_##type_var##concept< \
alpar@25
    72
    BOOST_FPTR ns::concept<type_var>::constraints> \
alpar@25
    73
    concept_checking_typedef_##type_var##concept
alpar@25
    74
alpar@25
    75
#define BOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \
alpar@25
    76
  typedef void (ns::concept <type_var1,type_var2>::* \
alpar@25
    77
     func##type_var1##type_var2##concept)(); \
alpar@25
    78
  template <func##type_var1##type_var2##concept Tp1_> \
alpar@25
    79
  struct concept_checking_##type_var1##type_var2##concept { }; \
alpar@25
    80
  typedef concept_checking_##type_var1##type_var2##concept< \
alpar@25
    81
    BOOST_FPTR ns::concept<type_var1,type_var2>::constraints> \
alpar@25
    82
    concept_checking_typedef_##type_var1##type_var2##concept
alpar@25
    83
alpar@25
    84
#define BOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \
alpar@25
    85
  typedef void (ns::concept <tv1,tv2,tv3>::* \
alpar@25
    86
     func##tv1##tv2##tv3##concept)(); \
alpar@25
    87
  template <func##tv1##tv2##tv3##concept Tp1_> \
alpar@25
    88
  struct concept_checking_##tv1##tv2##tv3##concept { }; \
alpar@25
    89
  typedef concept_checking_##tv1##tv2##tv3##concept< \
alpar@25
    90
    BOOST_FPTR ns::concept<tv1,tv2,tv3>::constraints> \
alpar@25
    91
    concept_checking_typedef_##tv1##tv2##tv3##concept
alpar@25
    92
alpar@25
    93
#define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
alpar@25
    94
  typedef void (ns::concept <tv1,tv2,tv3,tv4>::* \
alpar@25
    95
     func##tv1##tv2##tv3##tv4##concept)(); \
alpar@25
    96
  template <func##tv1##tv2##tv3##tv4##concept Tp1_> \
alpar@25
    97
  struct concept_checking_##tv1##tv2##tv3##tv4##concept { }; \
alpar@25
    98
  typedef concept_checking_##tv1##tv2##tv3##tv4##concept< \
alpar@25
    99
    BOOST_FPTR ns::concept<tv1,tv2,tv3,tv4>::constraints> \
alpar@25
   100
    concept_checking_typedef_##tv1##tv2##tv3##tv4##concept
alpar@25
   101
alpar@25
   102
alpar@25
   103
} // namespace lemon
alpar@25
   104
kpeter@27
   105
#endif // LEMON_CONCEPT_CHECKS_H