-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ranges::fill and ranges::fill_n (#904)
- Loading branch information
Showing
7 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\concepts_matrix.lst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <concepts> | ||
#include <ranges> | ||
#include <utility> | ||
|
||
#include <range_algorithm_support.hpp> | ||
|
||
struct instantiator { | ||
template <class Out> | ||
static constexpr void call() { | ||
using ranges::fill; | ||
{ | ||
int output[] = {13, 42, 1367}; | ||
const int value = 7; | ||
auto result = fill(ranges::begin(output), ranges::end(output), value); | ||
for (const auto& elem : output) { | ||
assert(elem == value); | ||
} | ||
assert(result == ranges::end(output)); | ||
} | ||
{ // Validate ranges overload | ||
int output[] = {13, 42, 1367}; | ||
const int value = 13; | ||
auto result = fill(output, value); | ||
for (const auto& elem : output) { | ||
assert(elem == value); | ||
} | ||
assert(result == ranges::end(output)); | ||
} | ||
} | ||
}; | ||
|
||
int main() { | ||
STATIC_ASSERT((test_out<instantiator>(), true)); | ||
test_out<instantiator>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\concepts_matrix.lst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <concepts> | ||
#include <ranges> | ||
#include <utility> | ||
|
||
#include <range_algorithm_support.hpp> | ||
|
||
struct instantiator { | ||
template <class Out> | ||
static constexpr void call() { | ||
using ranges::fill_n; | ||
|
||
const int expected_output[] = {13, 42, 1367}; | ||
const int value = 7; | ||
{ | ||
int output[] = {13, 42, 1367}; | ||
auto result = fill_n(ranges::begin(output), ranges::distance(output), value); | ||
for (const auto& elem : output) { | ||
assert(elem == value); | ||
} | ||
assert(result == ranges::end(output)); | ||
} | ||
{ | ||
int output[] = {13, 42, 1367}; | ||
auto result = fill_n(ranges::begin(output), 0, value); | ||
assert(ranges::equal(output, expected_output)); | ||
assert(result == ranges::begin(output)); | ||
} | ||
{ | ||
int output[] = {13, 42, 1367}; | ||
auto result = fill_n(ranges::begin(output), -1, value); | ||
assert(ranges::equal(output, expected_output)); | ||
assert(result == ranges::begin(output)); | ||
} | ||
} | ||
}; | ||
|
||
int main() { | ||
STATIC_ASSERT((test_out<instantiator>(), true)); | ||
test_out<instantiator>(); | ||
} |