concept/has_requirements.hh

00001 // This file is a part of Catsfoot.
00002 // Copyright (C) 2011  Uni Research
00003 //
00004 // This program is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HAS_REQUIREMENTS_HH
00018 # define HAS_REQUIREMENTS_HH
00019 
00020 # include "../type_traits/try_first.hh"
00021 # include "../type_traits/identity.hh"
00022 
00023 namespace catsfoot {
00024 
00025   namespace details {
00026     template <typename T, typename = typename T::requirements>
00027     std::true_type has_requirements_helper(try_first, T&&) {
00028       static_assert(always_false<T>::value,
00029                     "Cannot use this function");
00030       return 0;
00031     }
00032 
00033     template <typename T>
00034     std::false_type has_requirements_helper(try_second, T&&) {
00035       static_assert(always_false<T>::value,
00036                     "Cannot use this function");
00037       return 0;
00038     }
00039 
00041     template <typename T>
00042     struct has_requirements:
00043       public identity<
00044       decltype(has_requirements_helper(try_first(),
00045                                        std::declval<T>()))>::type
00046     {
00047     };
00048 
00049   }
00050 
00051 }
00052 
00053 #endif