Skip to content

Commit fb84004

Browse files
2 parents f525673 + fe89cb4 commit fb84004

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cppcon2025/cppcon_2025_slides.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,20 @@ void serialize(string_builder& b, const std::set<T>& v) { /* ... */ }
493493
Concepts let us say: **"If it walks like a duck and quacks like a duck..."**
494494
495495
```cpp
496-
// The NEW way - one function handles ALL array-like containers!
496+
template <typename T>
497+
concept container_but_not_string =
498+
requires(T a) {
499+
{ a.size() } -> std::convertible_to<std::size_t>;
500+
{
501+
a[std::declval<std::size_t>()]
502+
}; // check if elements are accessible for the subscript operator
503+
} && !std::is_same_v<T, std::string> &&
504+
!std::is_same_v<T, std::string_view> && !std::is_same_v<T, const char *>;
505+
```
506+
507+
---
508+
509+
```cpp
497510
template<typename T>
498511
requires(has_size_and_subscript<T>) // "If it has .size() and operator[]"
499512
void serialize(string_builder& b, const T& container) {

0 commit comments

Comments
 (0)