proxygen
AccessTest.cpp File Reference
#include <folly/container/Access.h>
#include <array>
#include <initializer_list>
#include <vector>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Classes

class  AccessTest
 

Functions

 TEST_F (AccessTest, size_vector)
 
 TEST_F (AccessTest, size_array)
 
 TEST_F (AccessTest, size_carray)
 
 TEST_F (AccessTest, size_initializer_list)
 
 TEST_F (AccessTest, empty_vector)
 
 TEST_F (AccessTest, empty_array)
 
 TEST_F (AccessTest, empty_carray)
 
 TEST_F (AccessTest, empty_initializer_list)
 
 TEST_F (AccessTest, data_vector)
 
 TEST_F (AccessTest, data_array)
 
 TEST_F (AccessTest, data_carray)
 
 TEST_F (AccessTest, data_initializer_list)
 

Function Documentation

TEST_F ( AccessTest  ,
size_vector   
)

Definition at line 27 of file AccessTest.cpp.

References EXPECT_EQ, and folly::size().

27  {
28  EXPECT_EQ(3, folly::size(std::vector<int>{1, 2, 3}));
29 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
TEST_F ( AccessTest  ,
size_array   
)

Definition at line 31 of file AccessTest.cpp.

References a, EXPECT_EQ, and folly::size().

31  {
32  constexpr auto const a = std::array<int, 3>{{1, 2, 3}};
33  constexpr auto const size = folly::size(a);
34  EXPECT_EQ(3, size);
35 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
char a
TEST_F ( AccessTest  ,
size_carray   
)

Definition at line 37 of file AccessTest.cpp.

References a, EXPECT_EQ, and folly::size().

37  {
38  constexpr int const a[3] = {1, 2, 3};
39  constexpr auto const size = folly::size(a);
40  EXPECT_EQ(3, size);
41 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
char a
TEST_F ( AccessTest  ,
size_initializer_list   
)

Definition at line 43 of file AccessTest.cpp.

References EXPECT_EQ, and folly::size().

43  {
44  EXPECT_EQ(3, folly::size({1, 2, 3}));
45  EXPECT_EQ(3, folly::size(std::initializer_list<int>{1, 2, 3}));
46 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
TEST_F ( AccessTest  ,
empty_vector   
)

Definition at line 48 of file AccessTest.cpp.

References folly::empty(), EXPECT_FALSE, and EXPECT_TRUE.

48  {
49  EXPECT_FALSE(folly::empty(std::vector<int>{1, 2, 3}));
50  EXPECT_TRUE(folly::empty(std::vector<int>{}));
51 }
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( AccessTest  ,
empty_array   
)

Definition at line 53 of file AccessTest.cpp.

References a, folly::empty(), EXPECT_FALSE, and EXPECT_TRUE.

53  {
54  {
55  constexpr auto const a = std::array<int, 3>{{1, 2, 3}};
56  constexpr auto const empty = folly::empty(a);
57  EXPECT_FALSE(empty);
58  }
59  {
60  constexpr auto const a = std::array<int, 0>{{}};
61  constexpr auto const empty = folly::empty(a);
62  EXPECT_TRUE(empty);
63  }
64 }
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
char a
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( AccessTest  ,
empty_carray   
)

Definition at line 66 of file AccessTest.cpp.

References a, folly::empty(), and EXPECT_FALSE.

66  {
67  constexpr int const a[3] = {1, 2, 3};
68  constexpr auto const empty = folly::empty(a);
69  EXPECT_FALSE(empty);
70  // zero-length arrays are not allowed in the language
71 }
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
char a
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( AccessTest  ,
empty_initializer_list   
)

Definition at line 73 of file AccessTest.cpp.

References folly::empty(), EXPECT_FALSE, and EXPECT_TRUE.

73  {
74  EXPECT_FALSE(folly::empty({1, 2, 3}));
75  EXPECT_FALSE(folly::empty(std::initializer_list<int>{1, 2, 3}));
76  EXPECT_TRUE(folly::empty(std::initializer_list<int>{}));
77 }
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( AccessTest  ,
data_vector   
)

Definition at line 79 of file AccessTest.cpp.

References folly::data(), and EXPECT_EQ.

79  {
80  EXPECT_EQ(1, *folly::data(std::vector<int>{1, 2, 3}));
81  auto v = std::vector<int>{1, 2, 3};
82  *folly::data(v) = 4;
83  EXPECT_EQ(4, v[0]);
84 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
TEST_F ( AccessTest  ,
data_array   
)

Definition at line 86 of file AccessTest.cpp.

References a, data, folly::data(), and EXPECT_EQ.

86  {
87  constexpr auto const a = std::array<int, 3>{{1, 2, 3}};
88  auto const data = folly::data(a); // not constexpr until C++17
89  EXPECT_EQ(1, *data);
90 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
char a
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
TEST_F ( AccessTest  ,
data_carray   
)

Definition at line 92 of file AccessTest.cpp.

References a, data, folly::data(), and EXPECT_EQ.

92  {
93  constexpr int const a[3] = {1, 2, 3};
94  auto const data = folly::data(a); // not constexpr until C++17
95  EXPECT_EQ(1, *data);
96 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
char a
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
TEST_F ( AccessTest  ,
data_initializer_list   
)

Definition at line 98 of file AccessTest.cpp.

References folly::data(), and EXPECT_EQ.

98  {
99  EXPECT_EQ(1, *folly::data({1, 2, 3}));
100  EXPECT_EQ(1, *folly::data(std::initializer_list<int>{1, 2, 3}));
101 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71