When the professor forgot to specify "recursion only"
class FlagTree {
T _data;
template <typename ...Args>
FlagTree(Args&&... args) :
_data(std::forward<Args>(args)...) {
}
FlagTree(const FlagTree& rhs) :
_data(rhs._data) {
}
FlagTree(FlagTree& rhs) :
FlagTree(const_cast<const FlagTree&>(rhs)) {
//override perfect forwarding from the variadic constructor
//otherwise it doesn't even compile, wtf's going on
}
};
struct Bar {
int a;
const std::source_location srce;
Bar(int b, const std::source_location s = std::source_location::current()) : a(b), srce(s) {}
}
void Foo(Bar arg0, const auto&... args) {
//do something
}
// integer "1" implicitly converts to Bar
Foo(1, 2, 3, 4, 5, 6);
int arr[] = {1, 2, 3};
for (int i = 0; i < 3; ++i) {
i[arr] = 0;
}
auto Add(const auto&... a) {
return (... + a);
}
int main() {
auto c0 = Add(-1, 2, -3);
auto c1 = Add(1.2, 3.4, -3.1415926535);
auto c2 = Add(string("unbox"), string("the"), string("cat"));
}
map<int, string> mp = {{1, "foo"}, {2, "bar"}};
auto entry = mp.extract(1);
entry.key() = 3;
mp.insert(std::move(entry));
src, srce (source)
dst, dest (destination)
first, last (denote range [a, b])
i, j, k, x, y, z (index for nested loops)
prev, curr, next (parent/child nodes)
arr (array)
vec (vector)
deq (deque)
que (queue)
ls, lst (list)
mp (map/hashmap)
addr (address)
ptr (pointer)
fn, fun, func (function)
const auto _ = cin.tie(nullptr)->sync_with_stdio(false);
//not portable
#if defined _WIN32 || defined _WIN64
inline char getchar_unlocked() { return static_cast<char>(_getchar_nolock()); }
#endif
template <std::signed_integral T>
T Read() {
T x; bool neg = false; char c{};
do { c = getchar_unlocked(); if (c == '-') neg = true; } while (c < '0');
for (x = c - '0'; '0' <= (c = getchar_unlocked()); x = (x << 3) + (x << 1) + c - '0') {}
return neg ? -x : x;
}
template <std::unsigned_integral T>
T Read() {
T x; char c{};
do { c = getchar_unlocked(); } while (c < '0');
for (x = c - '0'; '0' <= (c = getchar_unlocked()); x = (x << 3) + (x << 1) + c - '0');
return x;
}
Godbolt
Benchmark
C++ operator overloading guides
C++ Core Guidelines
Contest Events
Collaboration Coding