Commit e14ef532 authored by Aaryaman Sagar's avatar Aaryaman Sagar Committed by Facebook Github Bot

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
parent 3c127a77
......@@ -155,6 +155,18 @@ namespace folly {
template <typename T>
using _t = typename T::type;
/**
* A type trait to remove all const volatile and reference qualifiers on a
* type T
*/
template <typename T>
struct remove_cvref {
using type =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
};
template <typename T>
using remove_cvref_t = typename remove_cvref<T>::type;
/**
* type_t
*
......
......@@ -265,3 +265,49 @@ TEST(Traits, type_t) {
(::std::is_constructible<::container<std::string>, 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<remove_cvref_t<int>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int&&>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int&&>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int&>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int&>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int const>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int const>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int const&>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int const&>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int const&&>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int const&&>::type, int>::value));
// test all possible c-ref qualifiers with volatile
EXPECT_TRUE((std::is_same<remove_cvref_t<int volatile>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int volatile>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int volatile&&>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int volatile&&>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int volatile&>, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref<int volatile&>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int volatile const>, int>::value));
EXPECT_TRUE(
(std::is_same<remove_cvref<int volatile const>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int volatile const&>, int>::value));
EXPECT_TRUE(
(std::is_same<remove_cvref<int volatile const&>::type, int>::value));
EXPECT_TRUE((std::is_same<remove_cvref_t<int volatile const&&>, int>::value));
EXPECT_TRUE(
(std::is_same<remove_cvref<int volatile const&&>::type, int>::value));
}
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