Skip to content

Commit cf2ab69

Browse files
committed
replaced static filled function with repeating constructor
1 parent 52833ff commit cf2ab69

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

include/functional_vector.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ class functional_vector
5656
{
5757
}
5858

59+
// Creates a new vector by repeating a given element.
60+
//
61+
// example:
62+
// const functional_vector<std::string> filled_vector(3, "John");
63+
//
64+
// outcome:
65+
// filled_vector -> functional_vector<std::string>({ "John", "John", "John" })
66+
explicit functional_vector(size_t count, const T& element)
67+
: backing_vector_(count, element)
68+
{
69+
}
70+
5971
// Performs the functional `map` algorithm, in which every element of the resulting vector is the
6072
// output of applying the transform function on every element of this instance.
6173
//
@@ -1103,19 +1115,6 @@ class functional_vector
11031115
return *this;
11041116
}
11051117

1106-
// Creates a new vector of a given size, where all elements are equal
1107-
//
1108-
// example:
1109-
// const auto filled_vector = functional_vector<std::string>::filled("John", 3);
1110-
//
1111-
// outcome:
1112-
// filled_vector -> functional_vector<std::string>({ "John", "John", "John" })
1113-
[[nodiscard]] static functional_vector filled(const T& element, size_t count)
1114-
{
1115-
std::vector<T> backing_vector(count, element);
1116-
return functional_vector(std::move(backing_vector));
1117-
}
1118-
11191118
// Returns the size of the vector (how many elements it contains)
11201119
size_t size() const
11211120
{

tests/functional_vector_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,9 @@ TEST(FunctionalVectorTest, FillTest)
975975
EXPECT_EQ(functional_vector({ 7, 7, 7, 7, 7 }), vector_under_test);
976976
}
977977

978-
TEST(FunctionalVectorTest, FilledTest)
978+
TEST(FunctionalVectorTest, RepeatingConstructorTest)
979979
{
980-
const auto vector_under_test = functional_vector<std::string>::filled("John", 3);
980+
const functional_vector<std::string> vector_under_test(3, "John");
981981
EXPECT_EQ(functional_vector<std::string>({ "John", "John", "John" }), vector_under_test);
982982
}
983983

0 commit comments

Comments
 (0)