diff options
Diffstat (limited to '_posts/snippets/static_vs_inline_vs_unnamed_namespaces')
19 files changed, 54 insertions, 69 deletions
diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp index 91313f2..796ea85 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/shared.hpp @@ -1,7 +1,6 @@ #pragma once -inline int shared() -{ +inline int shared() { static int n = 0; return ++n; } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp index 668516a..330ba80 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/another.cpp @@ -2,12 +2,10 @@ #include <iostream> -inline void shared() -{ +inline void shared() { std::cout << "another.cpp: shared()\n"; } -void another() -{ +void another() { shared(); } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp index 4e32fb5..e278b9f 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/inline/weird/main.cpp @@ -2,13 +2,11 @@ #include <iostream> -inline void shared() -{ +inline void shared() { std::cout << "main.cpp: shared()\n"; } -int main() -{ +int main() { shared(); another(); return 0; diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/another.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/another.cpp index d8d53ae..f13b3a1 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/another.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/another.cpp @@ -1,7 +1,6 @@ #include "another.hpp" #include "shared.hpp" -void another() -{ +void another() { Test test; } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/main.cpp index 8d2043f..b3118c1 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/main.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/main.cpp @@ -1,8 +1,7 @@ #include "another.hpp" #include "shared.hpp" -int main() -{ +int main() { Test test; another(); return 0; diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/shared.hpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/shared.hpp index ef2d525..ef4da34 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/shared.hpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/separate_method_definitions/shared.hpp @@ -2,13 +2,11 @@ #include <iostream> -struct Test -{ +struct Test { Test(); }; -inline Test::Test() -{ +inline Test::Test() { static int x = 0; std::cout << ++x << '\n'; } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/main.cpp index 7fbeb56..fde1a43 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/main.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/main.cpp @@ -3,8 +3,7 @@ #include <iostream> -int main() -{ +int main() { std::cout << shared() << '\n'; std::cout << proxy() << '\n'; return 0; diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/proxy.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/proxy.cpp index a8eef26..78e4611 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/proxy.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/proxy.cpp @@ -1,7 +1,6 @@ #include "proxy.hpp" #include "shared.hpp" -int proxy() -{ +int proxy() { return shared(); } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/shared.hpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/shared.hpp index 6f812ab..647f49e 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/shared.hpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static/shared.hpp @@ -1,7 +1,6 @@ #pragma once -static int shared() -{ +static int shared() { static int n = 0; return ++n; } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/main.cpp index 7fbeb56..fde1a43 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/main.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/main.cpp @@ -3,8 +3,7 @@ #include <iostream> -int main() -{ +int main() { std::cout << shared() << '\n'; std::cout << proxy() << '\n'; return 0; diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/proxy.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/proxy.cpp index a8eef26..78e4611 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/proxy.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/proxy.cpp @@ -1,7 +1,6 @@ #include "proxy.hpp" #include "shared.hpp" -int proxy() -{ +int proxy() { return shared(); } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/shared.hpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/shared.hpp index a669247..28de441 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/shared.hpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/static_and_inline/shared.hpp @@ -1,7 +1,6 @@ #pragma once -static inline int shared() -{ +static inline int shared() { static int x = 0; return ++x; } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/main.cpp index 7fbeb56..fde1a43 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/main.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/main.cpp @@ -3,8 +3,7 @@ #include <iostream> -int main() -{ +int main() { std::cout << shared() << '\n'; std::cout << proxy() << '\n'; return 0; diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/proxy.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/proxy.cpp index a8eef26..78e4611 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/proxy.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/proxy.cpp @@ -1,7 +1,6 @@ #include "proxy.hpp" #include "shared.hpp" -int proxy() -{ +int proxy() { return shared(); } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/shared.hpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/shared.hpp index c64cc41..e21a00c 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/shared.hpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespace_and_inline/shared.hpp @@ -1,10 +1,10 @@ #pragma once -namespace -{ - inline int shared() - { - static int x = 0; - return ++x; - } +namespace { + +inline int shared() { + static int x = 0; + return ++x; +} + } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/another.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/another.cpp index 10128ef..cc7556d 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/another.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/another.cpp @@ -2,17 +2,18 @@ #include <iostream> -namespace -{ - struct Test - { - Test() { std::cout << "another.cpp: Test::Test()\n"; } +namespace { + +struct Test { + Test() { + std::cout << "another.cpp: Test::Test()\n"; + } + + float y = 1.; +}; - float y = 1.; - }; } -void another() -{ +void another() { Test test; } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/main.cpp index c0c0664..e383ded 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/main.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/ok/main.cpp @@ -2,18 +2,19 @@ #include <iostream> -namespace -{ - struct Test - { - Test() { std::cout << "main.cpp: Test::Test()\n"; } +namespace { + +struct Test { + Test() { + std::cout << "main.cpp: Test::Test()\n"; + } + + int x = 1; +}; - int x = 1; - }; } -int main() -{ +int main() { Test test; std::cout << test.x << '\n'; another(); diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/another.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/another.cpp index 8a125ec..0e0bff9 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/another.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/another.cpp @@ -2,14 +2,14 @@ #include <iostream> -struct Test -{ - Test() { std::cout << "another.cpp: Test::Test()\n"; } +struct Test { + Test() { + std::cout << "another.cpp: Test::Test()\n"; + } float y = 1.; }; -void another() -{ +void another() { Test test; } diff --git a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/main.cpp b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/main.cpp index 8ab8fb8..abd42b7 100644 --- a/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/main.cpp +++ b/_posts/snippets/static_vs_inline_vs_unnamed_namespaces/unnamed_namespaces/weird/main.cpp @@ -2,15 +2,15 @@ #include <iostream> -struct Test -{ - Test() { std::cout << "main.cpp: Test::Test()\n"; } +struct Test { + Test() { + std::cout << "main.cpp: Test::Test()\n"; + } int x = 1; }; -int main() -{ +int main() { Test test; std::cout << test.x << '\n'; another(); |