// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/template_util.h" #include "base/basictypes.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { namespace { struct AStruct {}; class AClass {}; enum AnEnum {}; class Parent {}; class Child : public Parent {}; // is_pointer COMPILE_ASSERT(!is_pointer::value, IsPointer); COMPILE_ASSERT(!is_pointer::value, IsPointer); COMPILE_ASSERT(is_pointer::value, IsPointer); COMPILE_ASSERT(is_pointer::value, IsPointer); // is_array COMPILE_ASSERT(!is_array::value, IsArray); COMPILE_ASSERT(!is_array::value, IsArray); COMPILE_ASSERT(!is_array::value, IsArray); COMPILE_ASSERT(is_array::value, IsArray); COMPILE_ASSERT(is_array::value, IsArray); COMPILE_ASSERT(is_array::value, IsArray); // is_non_const_reference COMPILE_ASSERT(!is_non_const_reference::value, IsNonConstReference); COMPILE_ASSERT(!is_non_const_reference::value, IsNonConstReference); COMPILE_ASSERT(is_non_const_reference::value, IsNonConstReference); // is_convertible // Extra parens needed to make preprocessor macro parsing happy. Otherwise, // it sees the equivalent of: // // (is_convertible < Child), (Parent > ::value) // // Silly C++. COMPILE_ASSERT( (is_convertible::value), IsConvertible); COMPILE_ASSERT(!(is_convertible::value), IsConvertible); COMPILE_ASSERT(!(is_convertible::value), IsConvertible); COMPILE_ASSERT( (is_convertible::value), IsConvertible); COMPILE_ASSERT( (is_convertible::value), IsConvertible); COMPILE_ASSERT(!(is_convertible::value), IsConvertible); // Array types are an easy corner case. Make sure to test that // it does indeed compile. COMPILE_ASSERT(!(is_convertible::value), IsConvertible); COMPILE_ASSERT(!(is_convertible::value), IsConvertible); COMPILE_ASSERT( (is_convertible::value), IsConvertible); // is_same COMPILE_ASSERT(!(is_same::value), IsSame); COMPILE_ASSERT(!(is_same::value), IsSame); COMPILE_ASSERT( (is_same::value), IsSame); COMPILE_ASSERT( (is_same::value), IsSame); COMPILE_ASSERT( (is_same::value), IsSame); COMPILE_ASSERT( (is_same::value), IsSame); COMPILE_ASSERT(!(is_same::value), IsSame); // is_class COMPILE_ASSERT(is_class::value, IsClass); COMPILE_ASSERT(is_class::value, IsClass); COMPILE_ASSERT(!is_class::value, IsClass); COMPILE_ASSERT(!is_class::value, IsClass); COMPILE_ASSERT(!is_class::value, IsClass); COMPILE_ASSERT(!is_class::value, IsClass); COMPILE_ASSERT(!is_class::value, IsClass); COMPILE_ASSERT(!is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(!is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(!is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(!is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(!is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(!is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(!is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer< int (AStruct::*)(int, int) const>::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer< int (AStruct::*)(int, int, int)>::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer< int (AStruct::*)(int, int, int) const>::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer< int (AStruct::*)(int, int, int, int)>::value, IsMemberFunctionPointer); COMPILE_ASSERT(is_member_function_pointer< int (AStruct::*)(int, int, int, int) const>::value, IsMemberFunctionPointer); // False because we don't have a specialization for 5 params yet. COMPILE_ASSERT(!is_member_function_pointer< int (AStruct::*)(int, int, int, int, int)>::value, IsMemberFunctionPointer); COMPILE_ASSERT(!is_member_function_pointer< int (AStruct::*)(int, int, int, int, int) const>::value, IsMemberFunctionPointer); } // namespace } // namespace base