首页
/
每日頭條
/
生活
/
線路代号30的表示方法
線路代号30的表示方法
更新时间:2026-08-03 03:37:38

線路代号30的表示方法?anon類模闆參數推導,今天小編就來聊一聊關于線路代号30的表示方法?接下來我們就一起去研究一下吧!

線路代号30的表示方法(C17in)1

線路代号30的表示方法

anon

類模闆參數推導

std::pair p(2, 4.5); // std::pair<int, double> std::tuple t(4, 3, 2.5); // std::tuple<int, int, double>

inline variable

// In a.hpp inline SomeType singletonVar;

每個翻譯單元都要include a.hpp,最後隻會保留一個

細化Evaluation order

a[i ] = i; // 等号右邊的現在規定會先計算完成 /* a.b a->b a->*b a(b1, b2, b3) b @= a a[b] a << b a >> b 現在都會a, b, c, d順序計算 */

guaranteed copy elision

std::mutex a_mutex; std::lock_guard<std::mutex> get_lock { return std::lock_guard<std::mutex>(a_mutex); // lock_guard沒有複制、移動構造函數。17之前這句不合法(盡管事實上都能編譯過)。17之後auto lock = get_lock;就合法了 }

if statement with initilizer

if (auto it = m.find(10); it != m.end) // return *it

structured binding

std::map<int, int> m; auto [iter, ok] = m.insert({1, 2}); // insert返回pair<Iterator, bool>

string_view

std::string cppstr = "Foo"; std::string_view cppstr_v(&cppstr[0], cppstr.size); cppstr[0] = 'A'; std::cout << cppstr_v; // Aoo

嵌套namespace

namespace a::b { // ... }

if constexpr

template<typename ... Ts> void f(Ts ... args) { if constexpr(sizeof... (args) > 0) f1(args..); else f1(default_arg); }

Fold 表達式

template<typename ... Ts> constexpr int sum(Ts... args) { return ( 0 ... args ); // = ( (0 arg0) arg1 ) arg2 ... } static_assert(10 == sum(2, 3, 5)); // static_assert可以沒有信息了

模闆非類型參數auto

template<auto C> struct Size { static const size_t size = sizeof(C); }; static_assert(Size<3>::size == sizeof(3)); static_assert(Size<(void*)0>::size == sizeof(void*));

lambda改進

struct Foo { int val; void f { (*this) { val = 100; }; // 複制了整個對象進lambda } }; Foo obj {42}; obj.f; assert(obj.val == 42); auto getSize = (auto o) { return sizeof(o); } // 這是constexpr了 static_assert(getSize(obj) == sizeof(Foo));

void_t,更方便的SFINAE

template< class, class = std::void_t<> > struct has_type_member : std::false_type { }; template< class T > struct has_type_member<T, std::void_t<typename T::type>> : std::true_type { };

{variant/optional/any}

optional<const char*> get_foo { if (...) return some_msg; else return {}; } std::cout << get_foo.value_or("Not found!");

variant<int, float> v, w; v = 12; int i = get<int>(v); w = get<int>(v); w = get<0>(v); // 同上 w = v; // 同上 get<double>(v); // ill formed

<algorithm>改進

std::sort(std::execution::par, std::begin(v), std::end(v)); // 并行版 std::vector<int> v2{ 1, 2, 4, 5, 0 }; assert(12 == std::reduce(std::execution::par, std::begin(v2), std::end(v2))); // 亂序版accumulate

filesystem

std::filesystem::copy("/etc/resolv.conf", "./resolv.conf", std::filesystem::copy_options::overwrite_existing); for (auto it = std::filesystem::recursive_directory_iterator("/usr/bin"); it != std::filesystem::recursive_directory_iterator; it) { std::cout << it->path << std::endl; }

Aligned dynamic allocation

namespace std { enum class align_val_t: size_t; }; void *operator new(std::size_t, std::align_val_t);// new overload 分配一段對齊的内存

在不同容器間移動結點

map<int, string> src {{1,"one"}, {2,"two"}, {3,"buckle my shoe"}}; map<int, string> dst {{3,"three"}}; dst.insert( src.extract( src.find(1) ) ); dst.insert( src.extract(2) );

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
西遊記十大神仙排行
西遊記十大神仙排行
《西遊記》作為四大名著之一,家喻戶曉,裡邊塑造了很多形形色色的角色,其中神仙們,也是可圈可點,小編今天就給大家列出神仙們的十大排名,排名依靠的是綜合實力和聲望。10、太乙天尊又稱太乙救苦天尊、尋聲救苦天尊、青華大帝,屬于道教尊神。大名鼎鼎的...
2026-08-03
四個令人着迷的數學猜想
四個令人着迷的數學猜想
很多時候我們都會發現很多世界聞名的數學難題,困擾了人類幾百年,但是看起來卻如此之簡單。比如中國人民最熟悉的哥德巴赫猜想,其實就是一個鄉村教師,哥德巴赫在閑暇裡注意到的數學規律,寫給歐拉之後,經過歐拉之手推向整個數學界;再比如一個表述極為容易...
2026-08-03
客廳可以放什麼花比較好
客廳可以放什麼花比較好
客廳可以放什麼花比較好?君子蘭君子蘭是石蒜科君子蘭屬的觀賞花卉原産于南非南部,是多年生草本植物一株成年的君子蘭,一晝夜能吸收1立升空氣,釋放80%的氧氣,就算是在極其微弱的光線下也能發生光合作用尤其是在北方,屋外白雪皚皚,人們為了保暖将門窗...
2026-08-03
傳感器靈敏系數單位
傳感器靈敏系數單位
在氣體傳感器中,PPM單位出現的頻率非常高,很多氣體檢測都是使用PPM單位,而且這些氣體一般都是有毒氣體,比如氨氣、臭氧、一氧化碳、氯氣、硫化氫、二氧化硫、VOC等。那麼氣體檢測中PPM單位是什麼意思呢?PPM是partpermillion...
2026-08-03
雅詩蘭黛持妝粉底液spf30
雅詩蘭黛持妝粉底液spf30
唇部保護不能忽略,唇紋是暴露年齡的關鍵部位!小編給大家推薦一款平價不貴的潤唇膏,而且還是大牌子家的哦!雅詩蘭黛防曬護唇膏專為唇部防護研制,具有SPF15防曬指數隔絕日光侵略,它的滋潤度很不錯,能夠有效阻止水分蒸發,全天候呵護清爽不黏膩,上妝...
2026-08-03
Copyright 2023-2026 - www.tftnews.com All Rights Reserved