Erich Keane
Software Engineer, iCDG, Intel
Erich.Keane@verizon.net
| ??= | # |
| ??( | [ |
| ??/ | \ |
| ??) | ] |
| ??' | ^ |
| ??< | { |
| ??! | | |
| ??> | } |
| ??- | ~ |
template<template<typename, typename> class T, typename IT, typename Alloc>
// ^^^^^ Only place in templates where
// class/template not interchangable
void DoThingToVector(T<IT, Alloc> vect)
{
std::cout << typeid(IT).name() <<std::endl;
}
//Now This is allowable:
template<template<typename, typename> typename T, typename IT, typename Alloc>
// ^^^^^
void DoThingToVector(T<IT, Alloc> vect)
{
std::cout << typeid(IT).name() <<std::endl;
}
auto x = foo(); // copy init
auto x{bar}; // direct initialization, is initializer_list!
int x = foo() // copy-initialization
int x{bar}; // direct-initializationauto x1 = {1, 2}; // x1 is std::initializer_list<int>
auto x2 = {1, 2.0}; // error, not a init-list type
auto x3{1, 2}; // error, not a single argument (used to be init-list)
auto x4 = {3}; // x4 is std::initializer_list<int>
auto x5 {3}; // x5 is int, used to be init-list
// Deprecated, returns whether an
// uncaught exception exists:
bool uncaught_exception() noexcept;
// New, returns COUNT of uncaught exceptions
int uncaught_exceptions() noexcept;
// Example:
void error_handler(){
try{
do_stuff();
}
catch(...)
{
// true, but no way to detect how deep!
uncaught_exception();
// number of exceptions deep
uncaught_exceptions();
error_handler(); // :)
}
}
int main(){
try{
do_thing();
}
catch(...)
{
uncaught_exception(); // true
uncaught_exceptions(); // 1
error_handler();
}
}// OPT OPT
inline namespace attributes_list name {...}[[noreturn]] // function doesn't return, see std::abort
[[carries_dependency]] // continues std::memory_order dependency chain
[[deprecated]] [[deprecated("just because!")]] // deprecates function
[[fallthrough]] // For a switch, indicates case fall through is intentional
[[nodiscard]] // Issue warning if return value isn't used
[[maybe_unused]] // unused warning is suppressed| Prefix | Type |
|---|---|
| u | char16_t |
| U | char32_t |
| L | wchar_t |
| u8 | UTF-8 |
//Right Fold: (pack op ...) AKA Unary Right Fold
template <typename ...Args>auto sum(Args... args){ return (args + ...);}
// Left Fold: (... op pack) AKA Unary Left Fold
template <typename ...Args>auto mod_things(Args... args){return (... % args);}
// Right Accumulation fold: (pack op ... op init) AKA Binary Right Fold
template <typename T, typename ...Args>auto str_acc(T init, Args... args){return (args + ... + init);}
// Left accumulation fold: (init op ... op pack) AKA Binary Left Fold
template <typename ...Args>bool bool_accum(bool init, Args... args){return (init && ... && init);}
int main()
{
sum(1,2,3,4,5);
// expansion is:1 + (2 + (3 + (4 + (5))
mod_things(2,3,4,5);
// expansion is:((2 % 3) % 4) % 5
str_acc(std::string("a"), "def", "ghi", "jkl");
// expansion is:"def" + ("ghi" + ("jkl" + "a"))
bool_accum(true, false, true, false, true);
// expansion is:(((init && false[1]) && true[2]) && false[3]) && true[4]
}
template <class ...Args>
pair<iterator, bool> try_emplace(const key_type&, Args&&...);
template <class ...Args>
pair<iterator, bool> try_emplace(key_type&, Args&&...);
template <class ...Args>
iterator try_emplace(const_iterator hint, const key_type&, Args&&...);
template <class ...Args>
iterator try_emplace(const_iterator hint, key_type&, Args&&...);
template <class M>
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
template <class M>
pair<iterator, bool> insert_or_assign(key_type& k, M&& obj);
template <class M>
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
template <class M>
iterator insert_or_assign(const_iterator hint, key_type& k, M&& obj);
//Partial List, specializations for fixed size arrays.
// Data also has non-const c and initializer list
// returns c.size
template<class C> constexpr auto size(const C& c)->decltype(c.size());
// returns c.empty
template<class C> constexpr auto empty(const C& c)->decltype(c.empty());
// returns c.data
template <class C> constexpr auto data(const C& c)->decltype(c.data());
// All of the following are legal and uniform:
vector<int> v{...};
int arr[] ={...};
if (std::size(v) == std::size(arr))
// Do a thing!