-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathTemplateParameter.h
40 lines (36 loc) · 1.36 KB
/
TemplateParameter.h
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
// -----------------------------------------------------------------------------------------------------------------------------
// Template parameter constraints
// See http://www.stroustrup.com/bs_faq2.html#constraints
// -----------------------------------------------------------------------------------------------------------------------------
namespace TemplateParameter
{
template<class T, class Base>
class SameOrDerivedFrom
{
private:
static void Constrain(T *const t)
{
CLANG_WNO_BEGIN("-Wunused-variable")
#pragma warning(suppress: 4189) // C4189: local variable is initialized but not referenced
Base *const b = t;
CLANG_WNO_END
}
public:
SameOrDerivedFrom()
{
CLANG_WNO_BEGIN("-Wunused-variable")
#pragma warning(suppress: 4189) // C4189: local variable is initialized but not referenced
void (*const p)(T *const t) = Constrain;
CLANG_WNO_END
}
};
template<class T>
struct Box
{
};
};