Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:51

0001 #ifndef FWCore_Utilities_mplVector_h
0002 #define FWCore_Utilities_mplVector_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Utilities
0006 // Class  :     edm::mpl::Vector
0007 //
0008 /**\class edm::mpl::Vector mplVector.h "FWCore/Utilities/interface/mplVector.h"
0009 
0010  Description: A meta-programming container of types
0011 
0012  Usage:
0013   The collection of types are specified in the template parameters.
0014   \code
0015     using Types = edm::mpl::Vector<A,B,C>;
0016   \endcode
0017 
0018   A check on if a type is held by the container can be done via the call to contains
0019   \code
0020   static_assert(edm::mpl::Vector<A,B,C>::contains<A>());
0021   \endcode
0022  
0023   It is possible to move through the sequence of types using the helper edm::mpl::Pop struct
0024   \code
0025      using edm::mpl;
0026      //get the first item
0027      static_assert(std::is_same_v<Pop<Vector<A,B>>::Item, A>);
0028  
0029      //get a container holding what remains
0030      static_assert(std::is_same_v<Vector<B>, Pop<Vector<A,B>::Remaining>);
0031  
0032      //check if more there
0033      static_assert(not Pop<Vector<B>>::empty);
0034      static_assert(Pop<Vector<>>::empty);
0035   \endcode
0036 */
0037 //
0038 // Original Author:  Chris Jones
0039 //         Created:  Tues, 21 Jul 2020 14:29:51 GMT
0040 //
0041 
0042 // system include files
0043 #include <type_traits>
0044 
0045 // user include files
0046 
0047 // forward declarations
0048 
0049 namespace edm {
0050   namespace mpl {
0051     template <typename... T>
0052     class Vector {
0053     public:
0054       ///Returns true if the type U is within the collection
0055       template <typename U>
0056       static constexpr bool contains() {
0057         return (std::is_same_v<U, T> || ...);
0058       }
0059     };
0060 
0061     template <typename T>
0062     struct Pop;
0063 
0064     template <typename F, typename... T>
0065     struct Pop<Vector<F, T...>> {
0066       constexpr static bool empty = false;
0067       using Item = F;
0068       using Remaining = Vector<T...>;
0069     };
0070 
0071     template <>
0072     struct Pop<Vector<>> {
0073       constexpr static bool empty = true;
0074       using Item = void;
0075       using Remaining = Vector<>;
0076     };
0077   }  // namespace mpl
0078 }  // namespace edm
0079 
0080 #endif