Object Lifetime: From Start to FinishdoSomethingElse(); int main() { doSomething(Foo(1), Foo(2).m_i, Foo(3).getBar(), string("World").c_str()), doSomethingElse(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 138 https://godbolt.org/z/nvY6EbTjsstruct doSomethingElse(); int main() { doSomething(Foo(1), Foo(2).m_i, Foo(3).getBar(), string("World").c_str()), doSomethingElse(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 139 https://godbolt.org/z/nvY6EbTjsstruct doSomethingElse(); int main() { doSomething(Foo(1), Foo(2).m_i, Foo(3).getBar(), string("World").c_str()), doSomethingElse(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 140 https://godbolt.org/z/nvY6EbTjsstruct0 码力 | 214 页 | 9.34 MB | 6 月前3
 C++高性能并行编程与优化 -  课件 - 15 C++ 系列课:字符与字符串给出警告),但是运行结果不对,或者还有可能崩溃。 泛型的 iostream 应运而生 • 得益于 C++ 的重载技术, cout 不用你手动指定类型,他 会自动识别参数的类型,帮你调用相应的格式化函数。 c_str 和 data 的区别 • s.c_str() 保证返回的是以 0 结尾的字符串首地址指针,总长度为 s.size() + 1 。 • s.data() 只保证返回长度为 s.size() iew name); // 超级追求性能的极客 c_str 和 data 的区别 • const char * 可以隐式转换为 string (为了方便) • string 不可以隐式转换为 const char * (安全起见) • 如果确实需要从 string 转换为 const char * ,请调用 .c_str() 这个成员函数 。 字符串的连接( + 运算符) • 用胖指针表示字符串 • C++ 的 string 克服了 C 语言 0 结尾字符串的缺点: • 字符串本身可以含有 ‘ \0’ 了,这下任何字符都众生平等。 • 末尾没有 ‘ \0’ 额外浪费的空间(除非调用 c_str 时)。 • 长度已经存储在 string 的成员里, size() 是 O(1) 的。 • 在尾部切片可以用 resize() 修改长度,无需写入字符串本身。 • string_view 和 span0 码力 | 162 页 | 40.20 MB | 1 年前3
 Reflection Is Not Contemplationproperty(class_builder& b, type type, std::string name) -> void { auto member_name = identifier{("m_" + name).c_str()}; append_field(b, member_name, type); method_prototype mp; object_type(mp, make_const(decl_of(b))); return_type(mp, make_lvalue_reference(make_const(type))); append_method(b, identifier{("get_" + name).c_str()}, mp, [member_name](method_builder& b){ append_return(b, make_field_expr( make_dere object_type(mp1, decl_of(b)); return_type(mp1, ^void); append_method(b, identifier{("set_" + name).c_str()}, mp1, [member_name](method_builder& b){ append_expr(b, make_operator_expr(0 码力 | 45 页 | 2.45 MB | 6 月前3
 Practical memory pool based allocators for Modern C++runOnFunction(llvm::Function & f) override { const auto pretty_name = boost::core::demangle(f.getName().str().c_str()); static const std::regex call_regex{R"(void instrument::type_reg<([^,]+),(.+),([^,]+)>\(\))"}; const auto pool_id = std::atoi(match[1].str().c_str()); const auto type = match[2].str(); const auto size = std::atoi(match[3].str().c_str()); std::cout << "Pool ID: " << pool_id0 码力 | 49 页 | 986.95 KB | 6 月前3
 Unraveling string_view: Basics, Benefits, and Best Practices<< sv << '\n'; name_ name• Some other methods in string which are not present in string_view • c_str: Since string_view cannot provide null terminated string guarantee. • capacity: No need, since there takeways 57 If you have a const std::string convert that to std::string_view. const std::string c_str{"hello"}; static constexpr std::string_view kStr{"hello"}; If you have a non-constructor function char*, then please: • Keep in mind that data() for string_view does not behave the same way that c_str() does for string. Always assume that it does not end with ‘\0’. • Check whether its empty() before0 码力 | 61 页 | 1.11 MB | 6 月前3
 Tracy: A Profiler You Don't Want to Missnt_thread_index(); tracy::SetThreadName(std::string("tbb worker #").append(std::to_string(tid)).c_str()); } } void on_scheduler_exit(bool is_worker) override { } }; 50 Tips & Tricks0 码力 | 84 页 | 8.70 MB | 6 月前3
 Tracy: A Profiler You Don't Want to Missnt_thread_index(); tracy::SetThreadName(std::string("tbb worker #").append(std::to_string(tid)).c_str()); } } void on_scheduler_exit(bool is_worker) override { } }; 50 Tips & Tricks0 码力 | 85 页 | 6.51 MB | 6 月前3
 Extending and Simplifying C++: Thoughts on Pattern Matching using 'is' and 'as', and Can C++ be 10x Simpler & Safer?auto myfile {fopen("xyzzy", "w")}; CPP2_UFCS(fprintf, myfile, "Hello %s with UFCS!” , CPP2_UFCS_0(c_str, std::move(s))); CPP2_UFCS_0(fclose, std::move(myfile)); 102UFCS - the beginning #define CPP2_UFCS(FUNCNAME0 码力 | 108 页 | 5.08 MB | 6 月前3
 A Physical Units Library for the Next C++[[nodiscard]] constexpr std::size_t size() const noexcept; [[nodiscard]] constexpr const CharT* c_str() const noexcept; [[nodiscard]] constexpr const CharT& operator[](std::size_t index) const noexcept;0 码力 | 172 页 | 6.17 MB | 6 月前3
 The Idris Tutorial Version 0.99E R 5. L A N G U A G E R E F E R E N C E v0. 99 public export data C_Types : Type -> Type where C_Str : C_Types String C_Float : C_Types Double C_Ptr : C_Types Ptr C_MPtr : C_Types ManagedPtr C_Unit t h e f ol l ow i n g i m p l i c i t p r oof as t h e fty ar gu m e n t t o foreign: FFun C_Str (FFun C_Str (FRet C_Ptr)) 5. 5. 4 C om p i l i n g f or e i gn c al l s ( T h i s s e c t i on as s u t h e LExp f or m as : LForeign (FStr "fileOpen") (FCon (sUN "C_Ptr")) [(FCon (sUN "C_Str"), f), (FCon (sUN "C_Str"), m)] ( As s u m i n g t h at f an d m s t an d f or t h e LExp r e p r e s e n t at0 码力 | 182 页 | 1.04 MB | 1 年前3
共 95 条
- 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 10
 
相关搜索词
 ObjectLifetimeFromStarttoFinishC++高性性能高性能并行编程优化课件15ReflectionIsNotContemplationPracticalmemorypoolbasedallocatorsforModernUnravelingstringviewBasicsBenefitsandBestPracticesTracyProfilerYouDonWantMissExtendingSimplifyingThoughtsonPatternMatchingusingisasCanbe10xSimplerSaferPhysicalUnitsLibrarytheNextTheIdrisTutorialVersion0.99













