Junxiao Shi | 3aba754 | 2016-12-24 02:42:52 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NFD_CORE_ASSERTS_HPP |
| 27 | #define NFD_CORE_ASSERTS_HPP |
| 28 | |
| 29 | #include "common.hpp" |
| 30 | #include <boost/concept/assert.hpp> |
| 31 | #include <boost/concept_check.hpp> |
| 32 | #include <type_traits> |
| 33 | |
| 34 | namespace nfd { |
| 35 | namespace detail { |
| 36 | |
| 37 | // As of Boost 1.54.0, the internal implementation of BOOST_CONCEPT_ASSERT does not allow |
| 38 | // multiple assertions on the same line, so we have to combine multiple concepts together. |
| 39 | |
| 40 | template<typename T> |
| 41 | class StlForwardIteratorConcept : public boost::ForwardIterator<T> |
| 42 | , public boost::DefaultConstructible<T> |
| 43 | { |
| 44 | }; |
| 45 | |
| 46 | } // namespace detail |
| 47 | } // namespace nfd |
| 48 | |
| 49 | /** \brief assert T is default constructible |
| 50 | * \sa http://en.cppreference.com/w/cpp/concept/DefaultConstructible |
| 51 | */ |
| 52 | #define NFD_ASSERT_DEFAULT_CONSTRUCTIBLE(T) \ |
| 53 | static_assert(std::is_default_constructible<T>::value, \ |
| 54 | #T " must be default-constructible"); \ |
| 55 | BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<T>)) |
| 56 | |
| 57 | /** \brief assert T is a forward iterator |
| 58 | * \sa http://en.cppreference.com/w/cpp/concept/ForwardIterator |
| 59 | * \note A forward iterator should be default constructible, but boost::ForwardIterator follows |
| 60 | * SGI standard which doesn't require DefaultConstructible, so a separate check is needed. |
| 61 | */ |
| 62 | #define NFD_ASSERT_FORWARD_ITERATOR(T) \ |
| 63 | BOOST_CONCEPT_ASSERT((::nfd::detail::StlForwardIteratorConcept<T>)); \ |
| 64 | static_assert(std::is_default_constructible<T>::value, \ |
| 65 | #T " must be default-constructible") |
| 66 | |
| 67 | #endif // NFD_CORE_ASSERTS_HPP |