From: Aaryaman Sagar Date: Thu, 28 Dec 2017 16:53:54 +0000 (-0800) Subject: Added remove_cvref X-Git-Tag: v2018.01.01.00~5 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e14ef53297ff23a1f3b1b01716708a416b080141;p=folly.git Added remove_cvref Summary: std::remove_cvref is like std::decay, but without the function to pointer and array to pointer decays Backport of http://en.cppreference.com/w/cpp/types/remove_cvref Reviewed By: yfeldblum Differential Revision: D6639513 fbshipit-source-id: 2a5e252678aacc09acf6ce4565872e7efb9b48f3 --- diff --git a/folly/Traits.h b/folly/Traits.h index fb797f37..cf094f09 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -155,6 +155,18 @@ namespace folly { template using _t = typename T::type; +/** + * A type trait to remove all const volatile and reference qualifiers on a + * type T + */ +template +struct remove_cvref { + using type = + typename std::remove_cv::type>::type; +}; +template +using remove_cvref_t = typename remove_cvref::type; + /** * type_t * diff --git a/folly/test/TraitsTest.cpp b/folly/test/TraitsTest.cpp index bfb3f7a7..2e36a3dd 100644 --- a/folly/test/TraitsTest.cpp +++ b/folly/test/TraitsTest.cpp @@ -265,3 +265,49 @@ TEST(Traits, type_t) { (::std::is_constructible<::container, some_tag, float>:: value)); } + +TEST(Traits, remove_cvref) { + using folly::remove_cvref; + using folly::remove_cvref_t; + + // test all possible c-ref qualifiers without volatile + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + // test all possible c-ref qualifiers with volatile + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE((std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE( + (std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE( + (std::is_same::type, int>::value)); + + EXPECT_TRUE((std::is_same, int>::value)); + EXPECT_TRUE( + (std::is_same::type, int>::value)); +}