1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58

base / types / is_instantiation_unittest.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/types/is_instantiation.h"

#include <map>
#include <string>
#include <vector>

namespace base {
namespace {

/////////////////////////////
// Single-argument template
/////////////////////////////

template <typename T1>
class SingleArg;

static_assert(is_instantiation<SingleArg, SingleArg<int>>);
static_assert(is_instantiation<SingleArg, SingleArg<char>>);
static_assert(is_instantiation<SingleArg, SingleArg<std::string>>);
static_assert(is_instantiation<SingleArg, SingleArg<std::vector<int>>>);

static_assert(!is_instantiation<SingleArg, int>);
static_assert(!is_instantiation<SingleArg, char>);
static_assert(!is_instantiation<SingleArg, std::vector<int>>);
static_assert(!is_instantiation<SingleArg, std::vector<SingleArg<int>>>);

static_assert(!is_instantiation<std::vector, SingleArg<int>>);

/////////////////////////////
// Variadic template
/////////////////////////////

template <typename...>
class Variadic;

static_assert(is_instantiation<Variadic, Variadic<>>);
static_assert(is_instantiation<Variadic, Variadic<int>>);
static_assert(is_instantiation<Variadic, Variadic<int, char>>);
static_assert(is_instantiation<Variadic, Variadic<int, char, Variadic<>>>);

static_assert(!is_instantiation<Variadic, SingleArg<int>>);
static_assert(!is_instantiation<SingleArg, Variadic<>>);
static_assert(!is_instantiation<SingleArg, Variadic<int>>);

/////////////////////////////
// Real types
/////////////////////////////

static_assert(is_instantiation<std::vector, std::vector<bool>>);
static_assert(is_instantiation<std::vector, std::vector<int>>);
static_assert(is_instantiation<std::map, std::map<int, char>>);

}  // namespace
}  // namespace base