Commit 3b18d435 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Cut FOLLY_CREATE_HAS_MEMBER_FN_TRAITS

Summary: [Folly] Cut `FOLLY_CREATE_HAS_MEMBER_FN_TRAITS` since it is unused and does not match the current invoker model, replacing uses which need it with `FOLLY_CREATE_MEMBER_INVOKER`.

Reviewed By: vitaut

Differential Revision: D23371070

fbshipit-source-id: 7fb0f5af21321a5056e06933ebd364a0a48a8fa1
parent d61f81cc
......@@ -859,7 +859,6 @@ if (BUILD_TESTS)
TEST glog_test SOURCES GLogTest.cpp
TEST group_varint_test SOURCES GroupVarintTest.cpp
TEST group_varint_test_ssse3 SOURCES GroupVarintTest.cpp
TEST has_member_fn_traits_test SOURCES HasMemberFnTraitsTest.cpp
TEST iterators_test SOURCES IteratorsTest.cpp
TEST indestructible_test SOURCES IndestructibleTest.cpp
TEST indexed_mem_pool_test BROKEN
......
......@@ -45,83 +45,6 @@
std::true_type, \
std::false_type>::type
#define FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, cv_qual) \
template <typename TTheClass_, typename RTheReturn_, typename... TTheArgs_> \
struct classname##__folly_traits_impl__< \
TTheClass_, \
RTheReturn_(TTheArgs_...) cv_qual> { \
template < \
typename UTheClass_, \
RTheReturn_ (UTheClass_::*)(TTheArgs_...) cv_qual> \
struct sfinae {}; \
template <typename UTheClass_> \
static std::true_type test(sfinae<UTheClass_, &UTheClass_::func_name>*); \
template <typename> \
static std::false_type test(...); \
}
/*
* The FOLLY_CREATE_HAS_MEMBER_FN_TRAITS is used to create traits
* classes that check for the existence of a member function with
* a given name and signature. It currently does not support
* checking for inherited members.
*
* Such classes receive two template parameters: the class to be checked
* and the signature of the member function. A static boolean field
* named `value` (which is also constexpr) tells whether such member
* function exists.
*
* Each traits class created is bound only to the member name, not to
* its signature nor to the type of the class containing it.
*
* Say you need to know if a given class has a member function named
* `test` with the following signature:
*
* int test() const;
*
* You'd need this macro to create a traits class to check for a member
* named `test`, and then use this traits class to check for the signature:
*
* namespace {
*
* FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_test_traits, test);
*
* } // unnamed-namespace
*
* void some_func() {
* cout << "Does class Foo have a member int test() const? "
* << boolalpha << has_test_traits<Foo, int() const>::value;
* }
*
* You can use the same traits class to test for a completely different
* signature, on a completely different class, as long as the member name
* is the same:
*
* void some_func() {
* cout << "Does class Foo have a member int test()? "
* << boolalpha << has_test_traits<Foo, int()>::value;
* cout << "Does class Foo have a member int test() const? "
* << boolalpha << has_test_traits<Foo, int() const>::value;
* cout << "Does class Bar have a member double test(const string&, long)? "
* << boolalpha << has_test_traits<Bar, double(const string&, long)>::value;
* }
*
* @author: Marcelo Juchem <marcelo@fb.com>
*/
#define FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(classname, func_name) \
template <typename, typename> \
struct classname##__folly_traits_impl__; \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, ); \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, const); \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
classname, func_name, /* nolint */ volatile); \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
classname, func_name, /* nolint */ volatile const); \
template <typename TTheClass_, typename TTheSignature_> \
using classname = \
decltype(classname##__folly_traits_impl__<TTheClass_, TTheSignature_>:: \
template test<TTheClass_>(nullptr))
namespace folly {
template <typename...>
......
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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.
*/
/*
* @author: Marcelo Juchem <marcelo@fb.com>
*/
#include <folly/Traits.h>
#include <folly/portability/GTest.h>
#include <glog/logging.h>
#include <string>
using namespace std;
using namespace folly;
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_test, test);
struct Foo {
int test();
int test() const;
string test(const string&) const;
};
struct Bar {
int test();
double test(int, long);
long test(int) const;
};
struct Gaz {
void test();
void test() const;
void test() /* nolint */ volatile;
void test() const /* nolint */ volatile;
};
struct NoCV {
void test();
};
struct Const {
void test() const;
};
struct Volatile {
void test() /* nolint */ volatile;
};
struct CV {
void test() const /* nolint */ volatile;
};
bool log_value(const char* what, bool result) {
LOG(INFO) << what << ": " << boolalpha << result;
return result;
}
#define LOG_VALUE(x) log_value(#x, x)
TEST(HasMemberFnTraits, DirectMembers) {
EXPECT_TRUE(LOG_VALUE((has_test<Foo, int()>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Foo, int() const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Foo, double(int, long)>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Foo, string(const string&) const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Foo, long(int) const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Foo, string(string) const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Bar, int()>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Bar, int() const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Bar, double(int, long)>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(const string&) const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Bar, long(int) const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(string) const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void()>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() /* nolint */ volatile>::value)));
EXPECT_TRUE(
LOG_VALUE((has_test<Gaz, void() const /* nolint */ volatile>::value)));
EXPECT_TRUE(
LOG_VALUE((has_test<Gaz, void() /* nolint */ volatile const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<NoCV, void()>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const>::value)));
EXPECT_FALSE(
LOG_VALUE((has_test<NoCV, void() /* nolint */ volatile>::value)));
EXPECT_FALSE(
LOG_VALUE((has_test<NoCV, void() const /* nolint */ volatile>::value)));
EXPECT_FALSE(
LOG_VALUE((has_test<NoCV, void() /* nolint */ volatile const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Const, void()>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Const, void() const>::value)));
EXPECT_FALSE(
LOG_VALUE((has_test<Const, void() /* nolint */ volatile>::value)));
EXPECT_FALSE(
LOG_VALUE((has_test<Const, void() const /* nolint */ volatile>::value)));
EXPECT_FALSE(
LOG_VALUE((has_test<Const, void() /* nolint */ volatile const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void()>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const>::value)));
EXPECT_TRUE(
LOG_VALUE((has_test<Volatile, void() /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE(
(has_test<Volatile, void() const /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE(
(has_test<Volatile, void() /* nolint */ volatile const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<CV, void()>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<CV, void() const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<CV, void() /* nolint */ volatile>::value)));
EXPECT_TRUE(
LOG_VALUE((has_test<CV, void() const /* nolint */ volatile>::value)));
EXPECT_TRUE(
LOG_VALUE((has_test<CV, void() /* nolint */ volatile const>::value)));
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......@@ -43,9 +43,6 @@ TEST(Traits, has_member_type) {
EXPECT_TRUE((is_same<true_type, has_member_type_x<membership_yes>>::value));
}
// Note: FOLLY_CREATE_HAS_MEMBER_FN_TRAITS tests are in
// folly/test/HasMemberFnTraitsTest.cpp.
struct T1 {}; // old-style IsRelocatable, below
struct T2 {}; // old-style IsRelocatable, below
struct T3 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment