Skip to content

Commit 148addf

Browse files
committed
alignof/as, attribute, raw string literal
1 parent 707985f commit 148addf

11 files changed

+171
-4
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "alignof_alignas.h"
2+
3+
NS_BEGIN( elloop )
4+
NS_BEGIN( alignof_alignas )
5+
6+
TEST( Align, Alignof ) {
7+
#ifdef _MSC_VER
8+
#else
9+
int a;
10+
long long ll;
11+
auto & c = ll;
12+
char carry[1024];
13+
//psln( alignof( int ) );
14+
#endif
15+
16+
}
17+
18+
TEST( Align, Alignas ) {
19+
#ifdef _MSC_VER
20+
#else
21+
alignas(10) char c;
22+
alignas( double ) char c1;
23+
alignas(alignof(double)) c2;
24+
#endif
25+
26+
}
27+
28+
NS_END( alignof_alignas )
29+
NS_END( elloop )
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifdef _MSC_VER
2+
#pragma once
3+
#else
4+
_Pragma( "once" )
5+
#endif
6+
#include "inc.h"
7+
8+
NS_BEGIN( elloop )
9+
NS_BEGIN( alignof_alignas )
10+
11+
12+
13+
// ALIGNOF is like sizeof, it return a std::size_t type, indicate how many
14+
// bytes the data is align. it's a platform related value.
15+
16+
// TODO: followings wait to be completed.
17+
// ALIGNAS
18+
19+
// std::align
20+
// std::align_storage
21+
// std::align_union
22+
23+
NS_END(alignof_alignas )
24+
NS_END(elloop )

understanding-c++11/attribute.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "attribute.h"
2+
3+
NS_BEGIN( elloop )
4+
NS_BEGIN( attribute )
5+
6+
#ifdef _MSC_VER
7+
#else
8+
[[noreturn]]void throwAway() {
9+
throw "away";
10+
}
11+
#endif
12+
13+
14+
void foo() {
15+
pln( "in foo" );
16+
#ifdef _MSC_VER
17+
pln( "vc don't work" );
18+
#else
19+
throwAway();
20+
#endif
21+
pln( "can't reach here" );
22+
}
23+
24+
TEST( Attribute, NoReturn ) {
25+
foo();
26+
}
27+
28+
29+
30+
NS_END( attribute )
31+
NS_END( elloop )

understanding-c++11/attribute.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifdef _MSC_VER
2+
#pragma once
3+
#else
4+
_Pragma( "once" )
5+
#endif
6+
#include "inc.h"
7+
8+
NS_BEGIN( elloop )
9+
NS_BEGIN( attribute )
10+
11+
// there are only two attributes in cpp11:
12+
// 1. [[noreturn]]
13+
// 2. [[carries_dependency]]
14+
15+
#ifdef _MSC_VER
16+
#else
17+
[[noreturn]]void throwAway();
18+
#endif
19+
20+
NS_END(attribute )
21+
NS_END(elloop )
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "raw_string_literal.h"
2+
3+
NS_BEGIN( elloop )
4+
NS_BEGIN( raw_string_literal )
5+
6+
TEST( RawStringLiteral, Test ) {
7+
using std::cout;
8+
using string = std::string;
9+
cout << R"(hello\nworld)";
10+
string s = R"(hello\nworld)";
11+
EXPECT_EQ( "hello\\nworld", s );
12+
13+
//cout << u8R"(ÄãºÃ)";
14+
//cout << uR"(hello)";
15+
16+
17+
}
18+
19+
NS_END( raw_string_literal )
20+
NS_END( elloop )
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifdef _MSC_VER
2+
#pragma once
3+
#else
4+
_Pragma( "once" )
5+
#endif
6+
#include "inc.h"
7+
8+
NS_BEGIN( elloop )
9+
NS_BEGIN( raw_string_literal )
10+
11+
12+
13+
NS_END(raw_string_literal )
14+
NS_END(elloop )

understanding-c++11/todo_next.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/*
2-
1. constexpr
3-
2. std::function
4-
3. template varargs
52
3+
// 2015/3/27
4+
// 1. rvalue, move semantic
5+
// 2. constexpr
6+
// 3. unicode
7+
8+
// test tuple, function
69
710
*/

understanding-c++11/understanding-c++11.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
</Link>
8080
</ItemDefinitionGroup>
8181
<ItemGroup>
82+
<ClCompile Include="alignof_alignas.cpp" />
83+
<ClCompile Include="attribute.cpp" />
8284
<ClCompile Include="auto.cpp" />
8385
<ClCompile Include="compatibility.cpp" />
8486
<ClCompile Include="constructor_test.cpp" />
@@ -88,6 +90,7 @@
8890
<ClCompile Include="main.cpp" />
8991
<ClCompile Include="pod_test.cpp" />
9092
<ClCompile Include="range_based_for_loop.cpp" />
93+
<ClCompile Include="raw_string_literal.cpp" />
9194
<ClCompile Include="SFINEA.cpp" />
9295
<ClCompile Include="smart_pointer.cpp" />
9396
<ClCompile Include="strongly_typed_enum.cpp" />
@@ -102,6 +105,8 @@
102105
<ClCompile Include="variadic_template.cpp" />
103106
</ItemGroup>
104107
<ItemGroup>
108+
<ClInclude Include="alignof_alignas.h" />
109+
<ClInclude Include="attribute.h" />
105110
<ClInclude Include="auto.h" />
106111
<ClInclude Include="decltype.h" />
107112
<ClInclude Include="inline_namespace.h" />
@@ -116,6 +121,7 @@
116121
<ClInclude Include="pod_test.h" />
117122
<ClInclude Include="print_util.h" />
118123
<ClInclude Include="range_based_for_loop.h" />
124+
<ClInclude Include="raw_string_literal.h" />
119125
<ClInclude Include="SFINEA.h" />
120126
<ClInclude Include="smart_pointer.h" />
121127
<ClInclude Include="strongly_typed_enum.h" />

understanding-c++11/understanding-c++11.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
<ClCompile Include="variadic_template.cpp">
5757
<Filter>c++11</Filter>
5858
</ClCompile>
59+
<ClCompile Include="alignof_alignas.cpp" />
60+
<ClCompile Include="attribute.cpp" />
61+
<ClCompile Include="raw_string_literal.cpp" />
5962
</ItemGroup>
6063
<ItemGroup>
6164
<ClInclude Include="inc.h">
@@ -126,6 +129,9 @@
126129
<ClInclude Include="variadic_template.h">
127130
<Filter>c++11</Filter>
128131
</ClInclude>
132+
<ClInclude Include="alignof_alignas.h" />
133+
<ClInclude Include="attribute.h" />
134+
<ClInclude Include="raw_string_literal.h" />
129135
</ItemGroup>
130136
<ItemGroup>
131137
<Filter Include="include">

understanding-c++11/variadic_template.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ TEST(VariadicTemplate, TemplateVariadicTemplate) {
9090
TEST(VariadicTemplate, PerfectForwardUsingVariadicTemplate) {
9191
Fa fa;
9292
Fb fb;
93-
build<MultiTypes>(fa, fb);
93+
auto mul = build<MultiTypes>(fa, fb);
94+
//Fa fa1 = mul.t_;
95+
EXPECT_EQ( &mul.t_, &fa );
96+
// how to find fb in mul?
97+
9498
}
9599

96100
NS_END( variadic_template )

0 commit comments

Comments
 (0)