// Copyright 2022 DeepMind Technologies Limited // // 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 // // http://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 "func_traits.h" #include #include #include #include namespace mujoco::util { namespace { TEST(FuncTraitsTest, IsCallable) { EXPECT_FALSE(is_callable_v); EXPECT_TRUE(is_callable_v); EXPECT_TRUE(is_callable_v); EXPECT_TRUE((is_callable_v)); EXPECT_TRUE(is_callable_v>); { auto lambda = [](){}; EXPECT_TRUE(is_callable_v); } { auto mutable_lambda = []() mutable {}; EXPECT_TRUE(is_callable_v); } { struct Functor { void operator()() {} }; EXPECT_TRUE(is_callable_v); } { struct ConstFunctor { void operator()() const {} }; EXPECT_TRUE(is_callable_v); } { struct NotCallable { void Foo() {} }; EXPECT_FALSE(is_callable_v); EXPECT_FALSE(is_callable_v); } } TEST(FuncTraitsTest, FuncArgType) { static_assert(std::is_same_v< func_arg_t, void >); static_assert(std::is_same_v< func_arg_t, int >); static_assert(std::is_same_v< func_arg_t, int&& >); static_assert(std::is_same_v< func_arg_t, int&& >); static_assert(std::is_same_v< func_arg_t, char& >); static_assert(std::is_same_v< func_arg_t, const float& >); static_assert(std::is_same_v< func_arg_t, void >); static_assert(std::is_same_v< func_arg_t, void >); { auto lambda = [](bool, double&, float&&){}; static_assert(std::is_same_v< func_arg_t, bool >); static_assert(std::is_same_v< func_arg_t, bool >); static_assert(std::is_same_v< func_arg_t, double& >); static_assert(std::is_same_v< func_arg_t, float&& >); static_assert(std::is_same_v< func_arg_t, void >); static_assert(std::is_same_v< func_arg_t, void >); } { struct Functor { void operator()(char, void*) {} }; static_assert(std::is_same_v< func_arg_t, char >); static_assert(std::is_same_v< func_arg_t, char >); static_assert(std::is_same_v< func_arg_t, void* >); static_assert(std::is_same_v< func_arg_t, void >); static_assert(std::is_same_v< func_arg_t, void >); } } TEST(FuncTraitsTest, FuncArgCount) { EXPECT_EQ(func_arg_count_v, 0); EXPECT_EQ(func_arg_count_v, 1); EXPECT_EQ(func_arg_count_v, 3); { auto lambda = [](bool, double&, float&&){}; EXPECT_EQ(func_arg_count_v, 3); } { struct Functor { void operator()(char, void*) {} }; EXPECT_EQ(func_arg_count_v, 2); } } } // namespace } // namespace mujoco::util