1 //===-- main.cpp ------------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 #include <tuple> 9 10 template <int Arg> 11 class TestObj 12 { 13 public: 14 int getArg() 15 { 16 return Arg; 17 } 18 }; 19 20 //---------------------------------------------------------------------- 21 // Define a template class that we can specialize with an enumeration 22 //---------------------------------------------------------------------- 23 enum class EnumType 24 { 25 Member, 26 Subclass 27 }; 28 29 template <EnumType Arg> class EnumTemplate; 30 31 //---------------------------------------------------------------------- 32 // Specialization for use when "Arg" is "EnumType::Member" 33 //---------------------------------------------------------------------- 34 template <> 35 class EnumTemplate<EnumType::Member> 36 { 37 public: 38 EnumTemplate(int m) : 39 m_member(m) 40 { 41 } 42 43 int getMember() const 44 { 45 return m_member; 46 } 47 48 protected: 49 int m_member; 50 }; 51 52 //---------------------------------------------------------------------- 53 // Specialization for use when "Arg" is "EnumType::Subclass" 54 //---------------------------------------------------------------------- 55 template <> 56 class EnumTemplate<EnumType::Subclass> : 57 public EnumTemplate<EnumType::Member> 58 { 59 public: 60 EnumTemplate(int m) : EnumTemplate<EnumType::Member>(m) 61 { 62 } 63 }; 64 65 template <typename FLOAT> struct T1 { FLOAT f = 1.5; }; 66 template <typename FLOAT> struct T2 { FLOAT f = 2.5; int i = 42; }; 67 template <typename FLOAT, template <typename> class ...Args> class C { std::tuple<Args<FLOAT>...> V; }; 68 69 int main(int argc, char **argv) 70 { 71 TestObj<1> testpos; 72 TestObj<-1> testneg; 73 EnumTemplate<EnumType::Member> member(123); 74 EnumTemplate<EnumType::Subclass> subclass(123*2); 75 C<float, T1> c1; 76 C<double, T1, T2> c2; 77 return testpos.getArg() - testneg.getArg() + member.getMember()*2 - subclass.getMember(); // Breakpoint 1 78 } 79