aboutsummaryrefslogtreecommitdiffstats
path: root/cxx11
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2012-10-19 14:48:55 -0400
committerAlec Thomas <alec@swapoff.org>2012-10-19 14:48:55 -0400
commite88636d40577776db26d34d8adacddbba5bd6da8 (patch)
tree22042c46c03538998a87b4bc7ccbf435d5dea1ba /cxx11
parent92dc19d8a0eaea4aac6327490695420deb226218 (diff)
A bunch of minor build fixes. Started README.
Diffstat (limited to 'cxx11')
-rw-r--r--cxx11/c++11-test-__func__-N2340.cpp8
-rw-r--r--cxx11/c++11-test-auto-N2546.cpp12
-rw-r--r--cxx11/c++11-test-constexpr-N2235.cpp19
-rw-r--r--cxx11/c++11-test-cstdint.cpp10
-rw-r--r--cxx11/c++11-test-decltype-N2343.cpp11
-rw-r--r--cxx11/c++11-test-lambda-N2927.cpp5
-rw-r--r--cxx11/c++11-test-long_long-N1811.cpp7
-rw-r--r--cxx11/c++11-test-nullptr-N2431.cpp5
-rw-r--r--cxx11/c++11-test-nullptr-N2431_fail_compile.cpp5
-rw-r--r--cxx11/c++11-test-rvalue_references-N2118.cpp15
-rw-r--r--cxx11/c++11-test-sizeof_member-N2253.cpp14
-rw-r--r--cxx11/c++11-test-static_assert-N1720.cpp5
-rw-r--r--cxx11/c++11-test-static_assert-N1720_fail_compile.cpp5
-rw-r--r--cxx11/c++11-test-variadic_templates-N2555.cpp23
-rw-r--r--cxx11/demo.cpp23
15 files changed, 167 insertions, 0 deletions
diff --git a/cxx11/c++11-test-__func__-N2340.cpp b/cxx11/c++11-test-__func__-N2340.cpp
new file mode 100644
index 0000000..c10dd18
--- /dev/null
+++ b/cxx11/c++11-test-__func__-N2340.cpp
@@ -0,0 +1,8 @@
+#include <cstring>
+
+int main()
+{
+ if (!__func__) { return 1; }
+ if(std::strlen(__func__) <= 0) { return 1; }
+ return 0;
+}
diff --git a/cxx11/c++11-test-auto-N2546.cpp b/cxx11/c++11-test-auto-N2546.cpp
new file mode 100644
index 0000000..dbff414
--- /dev/null
+++ b/cxx11/c++11-test-auto-N2546.cpp
@@ -0,0 +1,12 @@
+
+int main()
+{
+ auto i = 5;
+ auto f = 3.14159f;
+ auto d = 3.14159;
+ bool ret = (
+ (sizeof(f) < sizeof(d)) &&
+ (sizeof(i) == sizeof(int))
+ );
+ return ret ? 0 : 1;
+}
diff --git a/cxx11/c++11-test-constexpr-N2235.cpp b/cxx11/c++11-test-constexpr-N2235.cpp
new file mode 100644
index 0000000..9f969e4
--- /dev/null
+++ b/cxx11/c++11-test-constexpr-N2235.cpp
@@ -0,0 +1,19 @@
+constexpr int square(int x)
+{
+ return x*x;
+}
+
+constexpr int the_answer()
+{
+ return 42;
+}
+
+int main()
+{
+ int test_arr[square(3)];
+ bool ret = (
+ (square(the_answer()) == 1764) &&
+ (sizeof(test_arr)/sizeof(test_arr[0]) == 9)
+ );
+ return ret ? 0 : 1;
+}
diff --git a/cxx11/c++11-test-cstdint.cpp b/cxx11/c++11-test-cstdint.cpp
new file mode 100644
index 0000000..58d4381
--- /dev/null
+++ b/cxx11/c++11-test-cstdint.cpp
@@ -0,0 +1,10 @@
+#include <cstdint>
+int main()
+{
+ bool test =
+ (sizeof(int8_t) == 1) &&
+ (sizeof(int16_t) == 2) &&
+ (sizeof(int32_t) == 4) &&
+ (sizeof(int64_t) == 8);
+ return test ? 0 : 1;
+}
diff --git a/cxx11/c++11-test-decltype-N2343.cpp b/cxx11/c++11-test-decltype-N2343.cpp
new file mode 100644
index 0000000..d023885
--- /dev/null
+++ b/cxx11/c++11-test-decltype-N2343.cpp
@@ -0,0 +1,11 @@
+
+bool check_size(int i)
+{
+ return sizeof(int) == sizeof(decltype(i));
+}
+
+int main()
+{
+ bool ret = check_size(42);
+ return ret ? 0 : 1;
+}
diff --git a/cxx11/c++11-test-lambda-N2927.cpp b/cxx11/c++11-test-lambda-N2927.cpp
new file mode 100644
index 0000000..b86ad17
--- /dev/null
+++ b/cxx11/c++11-test-lambda-N2927.cpp
@@ -0,0 +1,5 @@
+int main()
+{
+ int ret = 0;
+ return ([&ret]() -> int { return ret; })();
+}
diff --git a/cxx11/c++11-test-long_long-N1811.cpp b/cxx11/c++11-test-long_long-N1811.cpp
new file mode 100644
index 0000000..2ae6988
--- /dev/null
+++ b/cxx11/c++11-test-long_long-N1811.cpp
@@ -0,0 +1,7 @@
+int main(void)
+{
+ long long l;
+ unsigned long long ul;
+
+ return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1;
+}
diff --git a/cxx11/c++11-test-nullptr-N2431.cpp b/cxx11/c++11-test-nullptr-N2431.cpp
new file mode 100644
index 0000000..6c5ae66
--- /dev/null
+++ b/cxx11/c++11-test-nullptr-N2431.cpp
@@ -0,0 +1,5 @@
+int main()
+{
+ int* test = nullptr;
+ return test ? 1 : 0;
+}
diff --git a/cxx11/c++11-test-nullptr-N2431_fail_compile.cpp b/cxx11/c++11-test-nullptr-N2431_fail_compile.cpp
new file mode 100644
index 0000000..5747f1b
--- /dev/null
+++ b/cxx11/c++11-test-nullptr-N2431_fail_compile.cpp
@@ -0,0 +1,5 @@
+int main()
+{
+ int i = nullptr;
+ return 1;
+}
diff --git a/cxx11/c++11-test-rvalue_references-N2118.cpp b/cxx11/c++11-test-rvalue_references-N2118.cpp
new file mode 100644
index 0000000..ef4e421
--- /dev/null
+++ b/cxx11/c++11-test-rvalue_references-N2118.cpp
@@ -0,0 +1,15 @@
+int foo(int& lvalue)
+{
+ return 123;
+}
+
+int foo(int&& rvalue)
+{
+ return 321;
+}
+
+int main()
+{
+ int i = 42;
+ return ((foo(i) == 123) && (foo(42) == 321)) ? 0 : 1;
+}
diff --git a/cxx11/c++11-test-sizeof_member-N2253.cpp b/cxx11/c++11-test-sizeof_member-N2253.cpp
new file mode 100644
index 0000000..3049ed1
--- /dev/null
+++ b/cxx11/c++11-test-sizeof_member-N2253.cpp
@@ -0,0 +1,14 @@
+struct foo {
+ char bar;
+ int baz;
+};
+
+int main(void)
+{
+ bool ret = (
+ (sizeof(foo::bar) == 1) &&
+ (sizeof(foo::baz) >= sizeof(foo::bar)) &&
+ (sizeof(foo) >= sizeof(foo::bar)+sizeof(foo::baz))
+ );
+ return ret ? 0 : 1;
+}
diff --git a/cxx11/c++11-test-static_assert-N1720.cpp b/cxx11/c++11-test-static_assert-N1720.cpp
new file mode 100644
index 0000000..eae3c9a
--- /dev/null
+++ b/cxx11/c++11-test-static_assert-N1720.cpp
@@ -0,0 +1,5 @@
+int main()
+{
+ static_assert(0 < 1, "your ordering of integers is screwed");
+ return 0;
+}
diff --git a/cxx11/c++11-test-static_assert-N1720_fail_compile.cpp b/cxx11/c++11-test-static_assert-N1720_fail_compile.cpp
new file mode 100644
index 0000000..d97b679
--- /dev/null
+++ b/cxx11/c++11-test-static_assert-N1720_fail_compile.cpp
@@ -0,0 +1,5 @@
+int main()
+{
+ static_assert(1 < 0, "this should fail");
+ return 0;
+}
diff --git a/cxx11/c++11-test-variadic_templates-N2555.cpp b/cxx11/c++11-test-variadic_templates-N2555.cpp
new file mode 100644
index 0000000..79fae84
--- /dev/null
+++ b/cxx11/c++11-test-variadic_templates-N2555.cpp
@@ -0,0 +1,23 @@
+int Accumulate()
+{
+ return 0;
+}
+
+template<typename T, typename... Ts>
+int Accumulate(T v, Ts... vs)
+{
+ return v + Accumulate(vs...);
+}
+
+template<int... Is>
+int CountElements()
+{
+ return sizeof...(Is);
+}
+
+int main()
+{
+ int acc = Accumulate(1, 2, 3, 4, -5);
+ int count = CountElements<1,2,3,4,5>();
+ return ((acc == 5) && (count == 5)) ? 0 : 1;
+}
diff --git a/cxx11/demo.cpp b/cxx11/demo.cpp
new file mode 100644
index 0000000..782681b
--- /dev/null
+++ b/cxx11/demo.cpp
@@ -0,0 +1,23 @@
+
+#include <iostream>
+
+int main()
+{
+ std::cout << "Testing\n";
+ std::cout << "Has static_assert: " <<
+#ifdef HAS_CXX11_STATIC_ASSERT
+ "yes :)"
+#else
+ "no"
+#endif
+ << "\n";
+ std::cout << "Has variadic templates: " <<
+#ifdef HAS_CXX11_VARIADIC_TEMPLATES
+ "yes :)"
+#else
+ "no"
+#endif
+ << "\n";
+ return 0;
+}
+