lemon/concept_check.h
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 08 Mar 2013 01:13:54 +0100
changeset 1046 387483bf0a56
parent 440 88ed40ad0d4f
child 1083 3e711ee55d31
permissions -rw-r--r--
Adjust image sizes in the documentation (#411)
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@25
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@25
     4
 *
alpar@440
     5
 * Copyright (C) 2003-2009
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@285
    19
// The contents of this file was inspired by the concept checking
alpar@285
    20
// utility of the BOOST library (http://www.boost.org).
alpar@25
    21
kpeter@53
    22
///\file
kpeter@53
    23
///\brief Basic utilities for concept checking.
kpeter@53
    24
///
kpeter@53
    25
kpeter@53
    26
#ifndef LEMON_CONCEPT_CHECK_H
kpeter@53
    27
#define LEMON_CONCEPT_CHECK_H
alpar@25
    28
alpar@25
    29
namespace lemon {
alpar@25
    30
alpar@25
    31
  /*
alpar@25
    32
    "inline" is used for ignore_unused_variable_warning()
alpar@25
    33
    and function_requires() to make sure there is no
alpar@25
    34
    overtarget with g++.
alpar@25
    35
  */
alpar@25
    36
alpar@25
    37
  template <class T> inline void ignore_unused_variable_warning(const T&) { }
alpar@997
    38
  template <class T1, class T2>
alpar@997
    39
  inline void ignore_unused_variable_warning(const T1&, const T2&) { }
alpar@997
    40
  template <class T1, class T2, class T3>
alpar@997
    41
  inline void ignore_unused_variable_warning(const T1&, const T2&,
alpar@997
    42
                                             const T3&) { }
alpar@997
    43
  template <class T1, class T2, class T3, class T4>
alpar@997
    44
  inline void ignore_unused_variable_warning(const T1&, const T2&,
alpar@997
    45
                                             const T3&, const T4&) { }
alpar@997
    46
  template <class T1, class T2, class T3, class T4, class T5>
alpar@997
    47
  inline void ignore_unused_variable_warning(const T1&, const T2&,
alpar@997
    48
                                             const T3&, const T4&,
alpar@997
    49
                                             const T5&) { }
alpar@997
    50
  template <class T1, class T2, class T3, class T4, class T5, class T6>
alpar@997
    51
  inline void ignore_unused_variable_warning(const T1&, const T2&,
alpar@997
    52
                                             const T3&, const T4&,
alpar@997
    53
                                             const T5&, const T6&) { }
alpar@25
    54
kpeter@53
    55
  ///\e
alpar@25
    56
  template <class Concept>
alpar@25
    57
  inline void function_requires()
alpar@25
    58
  {
alpar@25
    59
#if !defined(NDEBUG)
alpar@25
    60
    void (Concept::*x)() = & Concept::constraints;
alpar@25
    61
    ignore_unused_variable_warning(x);
alpar@25
    62
#endif
alpar@25
    63
  }
alpar@25
    64
kpeter@53
    65
  ///\e
alpar@25
    66
  template <typename Concept, typename Type>
alpar@25
    67
  inline void checkConcept() {
alpar@25
    68
#if !defined(NDEBUG)
alpar@25
    69
    typedef typename Concept::template Constraints<Type> ConceptCheck;
alpar@25
    70
    void (ConceptCheck::*x)() = & ConceptCheck::constraints;
alpar@25
    71
    ignore_unused_variable_warning(x);
alpar@25
    72
#endif
alpar@25
    73
  }
alpar@25
    74
alpar@25
    75
} // namespace lemon
alpar@25
    76
kpeter@53
    77
#endif // LEMON_CONCEPT_CHECK_H