// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "src/base/type_traits.h" #include #include #include #include #include namespace astc_codec { namespace base { TEST(TypeTraits, IsCallable) { class C; C* c = nullptr; auto lambda = [c](bool) -> C* { return nullptr; }; static_assert(is_callable_as::value, "simple function"); static_assert(is_callable_as::value, "function reference"); static_assert(is_callable_as::value, "function pointer"); static_assert(is_callable_as::value, "function with arguments and return type"); static_assert(is_callable_as::value, "lambda"); static_assert(is_callable_as, bool(int)>::value, "std::function"); static_assert(!is_callable_as::value, "int should not be callable"); static_assert(!is_callable_as::value, "incomplete type"); static_assert(!is_callable_as::value, "different arguments"); static_assert(!is_callable_as::value, "different return types"); static_assert(!is_callable_as::value, "slightly different return types"); static_assert(!is_callable_as::value, "more arguments"); static_assert(!is_callable_as::value, "less arguments"); static_assert(!is_callable_as::value, "bad required signature"); static_assert(is_callable_with_args::value, "simple function"); static_assert(is_callable_with_args::value, "function reference"); static_assert(is_callable_with_args::value, "function pointer"); static_assert(is_callable_with_args::value, "function with arguments and return type"); static_assert(is_callable_with_args::value, "lambda"); static_assert( is_callable_with_args, bool(int)>::value, "std::function"); static_assert(!is_callable_with_args::value, "int should not be callable"); static_assert(!is_callable_with_args::value, "incomplete type"); static_assert(!is_callable_with_args::value, "different arguments"); static_assert(is_callable_with_args::value, "different return types are ignored"); static_assert(is_callable_with_args::value, "slightly different return types are ignored"); static_assert(!is_callable_with_args::value, "more arguments"); static_assert(!is_callable_with_args::value, "less arguments"); static_assert(!is_callable_with_args::value, "bad required signature"); } TEST(TypeTraits, IsTemplateInstantiation) { static_assert(!is_template_instantiation_of::value, "int is not an instance of vector"); static_assert(!is_template_instantiation_of>, std::vector>::value, "list is not an instance of vector"); static_assert( is_template_instantiation_of, std::vector>::value, "std::vector is an instance of vector"); static_assert( is_template_instantiation_of>>, std::vector>::value, "nested std::vector<> is an instance of vector"); } TEST(TypeTraits, IsRange) { static_assert(is_range>::value, "vector<> should be detected as a range"); static_assert(is_range>>::value, "const list<> should be detected as a range"); static_assert(is_range, 10>>::value, "array<> should be detected as a range"); char arr[100]; static_assert(is_range::value, "C array should be detected as a range"); static_assert(is_range::value, "String literal should be detected as a range"); static_assert(!is_range::value, "int shouldn't be a range"); static_assert(!is_range::value, "int* shouldn't be a range"); static_assert(!is_range::value, "even const int* shouldn't be a range"); } } // namespace base } // namespace astc_codec