Skip to content

Commit

Permalink
[341] - Did you know that C++26 added user-generated static_assert me…
Browse files Browse the repository at this point in the history
…ssages?
  • Loading branch information
krzysztof-jusiak committed Jul 30, 2023
1 parent d697dd6 commit 4fdf572
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Tips

* [[341]](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/blob/master/tips/341.md) - Did you know that C++26 added user-generated static_assert messages?
* [[340]](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/blob/master/tips/340.md) - Did you know that C++26 added bind front and back to NTTP callables?
* [[339]](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/blob/master/tips/339.md) - Did you know about C++20 `std::next_permutation` algorithm?
* [[338]](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/blob/master/tips/338.md) - Did you know that C++26 added `@, $, and `` to the basic character set?
Expand Down
11 changes: 11 additions & 0 deletions tips/340.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ int main() {

</p></details><details><summary>Solutions</summary><p>

```cpp
template<auto Fn>
[[nodiscard]] constexpr auto bind_front(auto&& obj,auto&&...bound_args) {
return [=](auto&&...args){
return (obj.*Fn)(bound_args..., args...);
};
}
```
> https://godbolt.org/z/EExd3rdrx
</p></details>
27 changes: 27 additions & 0 deletions tips/341.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<details open><summary>Info</summary><p>

* **Did you know that C++26 added user-generated static_assert messages?**

* https://wg21.link/P2741

</p></details><details open><summary>Example</summary><p>

```cpp
static_assert(false, std::string_view{"message"});
```
> https://godbolt.org/z/njoWdn7T7
</p></details><details open><summary>Puzzle</summary><p>
* **Can you apply format for static_assert messages?**
```cpp
// TODO format
struct foo {};
static_assert(sizeof(foo) == 0, format("Unexpected sizeof: expected 0, got {}", sizeof(foo)));
```

> https://godbolt.org/z/eb4oq14aY
</p></details>

0 comments on commit 4fdf572

Please sign in to comment.