OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [g++.dg/] [template/] [sfinae12.C] - Blame information for rev 328

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 301 jeremybenn
// DR 339
2
//
3
// Test of the use of the ternary operator with SFINAE
4
 
5
// Boilerplate helpers
6
typedef char yes_type;
7
struct no_type { char data[2]; };
8
 
9
template T create_a();
10
template struct type { };
11
 
12
template struct enable_if { typedef T type; };
13
template struct enable_if { };
14
 
15
#define JOIN( X, Y ) DO_JOIN( X, Y )
16
#define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
17
#define DO_JOIN2( X, Y ) X##Y
18
 
19
template
20
typename enable_if<
21
           (sizeof((create_a()? create_a() : create_a()), 0) > 0),
22
           yes_type>::type
23
  check_ternary(int);
24
 
25
template no_type check_ternary(...);
26
 
27
template
28
struct has_ternary
29
{
30
  static const bool value =
31
    (sizeof(check_ternary(0)) == sizeof(yes_type));
32
};
33
 
34
#ifdef __GXX_EXPERIMENTAL_CXX0X__
35
#  define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
36
#else
37
#  define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
38
#endif
39
 
40
struct X { };
41
struct Y { operator bool(); };
42
 
43
STATIC_ASSERT((has_ternary::value));
44
STATIC_ASSERT((has_ternary::value));
45
STATIC_ASSERT((!has_ternary::value));
46
STATIC_ASSERT((!has_ternary::value));
47
STATIC_ASSERT((has_ternary::value));

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.