zoukankan      html  css  js  c++  java
  • 【leetcode】39. 组合总和

    39. 组合总和

     1 #include <iostream>
     2 #include <type_traits>
     3 using namespace std;
     4 
     5 //定义一个person类 class person
     6 class person{};
     7 
     8 class dog
     9 {
    10 };
    11 
    12 template <typename T>
    13 struct is_person
    14 {
    15     static const bool value = false;
    16 };
    17 
    18 template <>
    19 struct is_person<person>
    20 {
    21     static const bool value = true;
    22 };
    23 
    24 template <typename T, typename std::enable_if<is_person<T>::value, T>::type * = nullptr>
    25 void func(T t)
    26 {
    27     cout << "person stuff" << endl;
    28 }
    29 
    30 void func(int a)
    31 {
    32     cout << "int type" << endl;
    33 }
    34 
    35 
    36 template <typename T, typename std::enable_if<!is_person<T>::value, T>::type * = nullptr>
    37 void func(T t)
    38 {
    39     // do something;
    40     cout << "not person stuff" << endl;
    41 }
    42 
    43 int main()
    44 {
    45     func(5);        // int type
    46     func(person()); // person stuff
    47     func(dog());    // not person stuff
    48 }
    View Code
  • 相关阅读:
    UML序列图
    接口初探
    Discuz初探
    Vim指令学习
    UCenter Home代码研读之space.php
    建站须知
    linux指令之文件的创建、查询、修改
    InitPHP初探
    php环境搭建
    Zend Framework学习之Zend_Db 数据库操作
  • 原文地址:https://www.cnblogs.com/sunbines/p/14942028.html
Copyright © 2011-2022 走看看