Skip to content

Commit

Permalink
Merge pull request #554 from guwirth/enhancement/cpp11_examples
Browse files Browse the repository at this point in the history
narrow down C++11 issues:
  • Loading branch information
guwirth committed Jul 5, 2015
2 parents bdb373b + c95e288 commit 80b947f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 55 deletions.
5 changes: 2 additions & 3 deletions cxx-squid/src/test/resources/parser/own/C++11/decl-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const A* a = new A{ 0 };
decltype(a->x) x3; // type of x3 is double (declared type)
decltype((a->x)) x4 = x3; // type of x4 is const double& (lvalue expression)

//ToDo - make this work
//template <class T, class U>
//auto add(T t, U u) -> decltype(t + u); // return type depends on template parameters
template <class T, class U>
auto add(T t, U u) -> decltype(t + u); // return type depends on template parameters

int main()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <iostream>
#include <array>

//ToDo - make this work
//template<typename... Ts>
//constexpr auto make_array(Ts&&... ts)
//->std::array<std::common_type_t<Ts...>, sizeof...(ts)>
//{
// return{ std::forward<Ts>(ts)... };
//}
template<typename... Ts>
constexpr auto make_array(Ts&&... ts)
->std::array<std::common_type_t<Ts...>, sizeof...(ts)>
{
return{ std::forward<Ts>(ts)... };
}

int main()
{
Expand Down
30 changes: 15 additions & 15 deletions cxx-squid/src/test/resources/parser/own/C++11/parameter-pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

void tprintf(const char* format) // base function
{
std::cout << format;
std::cout << format;
}

//ToDo - make this work
//template<typename T, typename... Targs>
//void tprintf(const char* format, T value, Targs... Fargs) // recursive variadic function
//{
// for (; *format != '\0'; format++) {
// if (*format == '%') {
// std::cout << value;
// tprintf(format + 1, Fargs...); // recursive call
// return;
// }
// std::cout << *format;
// }
//}
template<typename T, typename... Targs>
void tprintf(const char* format, T value/*, Targs... Fargs*/) // recursive variadic function
{
for (; *format != '\0'; format++) {
if (*format == '%') {
std::cout << value;
tprintf(format + 1, Fargs...); // recursive call
return;
}
std::cout << *format;
}
}

int main()
{
tprintf("% world% %\n", "Hello", '!', 123);
return 0;
tprintf("% world% %\n", "Hello", '!', 123);
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#include <iostream>

//ToDo - make this work
// used as conversion
//constexpr long double operator"" _deg(long double deg)
//{
// return deg*3.141592 / 180;
//}
//
//// used with custom type
//struct mytype
//{
// mytype(unsigned long long m) :m(m) {}
// unsigned long long m;
//};
//mytype operator"" _mytype(unsigned long long n)
//{
// return mytype(n);
//}
//
//// used for side-effects
//void operator"" _print(const char* str)
//{
// std::cout << str;
//}
//
//int main() {
// double x = 90.0_deg;
// std::cout << std::fixed << x << '\n';
// mytype y = 123_mytype;
// std::cout << y.m << '\n';
// 0x123ABC_print;
//}
constexpr long double operator"" _deg(long double deg)
{
return deg*3.141592 / 180;
}

// used with custom type
struct mytype
{
mytype(unsigned long long m) :m(m) {}
unsigned long long m;
};
mytype operator"" _mytype(unsigned long long n)
{
return mytype(n);
}

// used for side-effects
void operator"" _print(const char* str)
{
std::cout << str;
}

//ToDo - make this work
int main() {
//double x = 90.0_deg;
std::cout << std::fixed << x << '\n';
//mytype y = 123_mytype;
std::cout << y.m << '\n';
//0x123ABC_print;
}

0 comments on commit 80b947f

Please sign in to comment.