-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[316] - Did you know about
std::rank/std::rank_v
type_trait to get …
…the rank of the array?
- Loading branch information
1 parent
29edba2
commit 2b73f42
Showing
3 changed files
with
63 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<details open><summary>Info</summary><p> | ||
|
||
* Did you know about `std::rank/std::rank_v` type_trait to get the rank of the array? | ||
|
||
* https://eel.is/c++draft/meta.unary.prop.query#lib:rank | ||
|
||
</p></details><details open><summary>Example</summary><p> | ||
|
||
```cpp | ||
static_assert(0 == std::rank_v<void>); | ||
static_assert(0 == std::rank_v<int>); | ||
static_assert(1 == std::rank_v<int[]>); | ||
static_assert(0 == std::rank_v<int[0]>); | ||
static_assert(1 == std::rank_v<int[1]>); | ||
static_assert(1 == std::rank_v<int[42]>); | ||
static_assert(2 == std::rank_v<int[][2]>); | ||
static_assert(2 == std::rank_v<int[1][2]>); | ||
static_assert(3 == std::rank_v<int[1][2][3]>); | ||
``` | ||
> https://godbolt.org/z/e657s3 | ||
</p></details><details open><summary>Puzzle</summary><p> | ||
> Can you implement standard compliant version of `std::rank_v`? | ||
```cpp | ||
static_assert(0 == rank_v<void>); | ||
static_assert(0 == rank_v<int>); | ||
static_assert(1 == rank_v<int[]>); | ||
static_assert(0 == rank_v<int[0]>); | ||
static_assert(1 == rank_v<int[1]>); | ||
static_assert(1 == rank_v<int[42]>); | ||
static_assert(2 == rank_v<int[][2]>); | ||
static_assert(2 == rank_v<int[1][2]>); | ||
static_assert(3 == rank_v<int[1][2][3]>); | ||
``` | ||
|
||
> https://godbolt.org/z/7Ms3W4TdP | ||
</p></details><details><summary>Solutions</summary><p> |