concept/parse_ids.hh

00001 // This file is a part of Catsfoot.
00002 // Copyright (C) 2011  Uni Research
00003 // Copyright (C) 2011  Valentin David
00004 //
00005 // This program is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser Public License
00016 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #ifndef PARSE_IDS_HH
00019 # define PARSE_IDS_HH
00020 
00021 # include <vector>
00022 # include <tuple>
00023 # include <string>
00024 # include "../type_traits/always_false.hh"
00025 
00026 namespace catsfoot {
00027 
00028   namespace details {
00029 
00031     template <typename T, typename... U, typename... V,
00032               typename = typename
00033               std::enable_if<sizeof...(V) == sizeof...(U)>::type>
00034     std::tuple<std::pair<T, U>...>
00035     zip_vec_tuple(const std::vector<T>& vec,
00036                   const std::tuple<U...>&,
00037                   V&&... v) {
00038       assert(vec.size() == sizeof...(V));
00039       return std::tuple<std::pair<T, U>...>{std::forward<V>(v)...};
00040     }
00041 
00043     template <typename T, typename... U, typename... V,
00044               typename = void,
00045               typename
00046 # ifndef DOC_GEN
00047               = typename
00048               std::enable_if<sizeof...(V) < sizeof...(U)>::type
00049 # endif
00050              >
00051     std::tuple<std::pair<T, U>...>
00052     zip_vec_tuple(const std::vector<T>& v,
00053                   const std::tuple<U...>& t,
00054                   V&&... values) {
00055       return zip_vec_tuple
00056         (v, t, std::forward<V>(values)...,
00057          std::pair
00058          <T, typename std::tuple_element<sizeof...(V), std::tuple<U...> >
00059           ::type>
00060          {v[sizeof...(V)], std::get<sizeof...(V)>(t)});
00061     }
00062 
00063 # ifdef  __CATSFOOT_ENABLE_TESTING_RT
00064 #  include "../extern_decl.hh"
00065 
00068     EXTERN
00069     std::vector<std::string>
00070     split_identifiers(const std::string&);
00071 # else
00072     template <typename T = std::string>
00073     std::vector<std::string>
00074     split_identifiers(const T&) {
00075       static_assert(details::always_false<T>::value,
00076                     "You probably called a functionality that is available "
00077                     "only if you link with the runtime library. In this case "
00078                     "include catsfoot_testing.hh instead of catsfoot.hh");
00079       return std::vector<std::string>{};
00080     }
00081 # endif
00082   }
00083 }
00084 
00085 #endif