2014-09-22 03:37:07 +02:00
|
|
|
|
/*
|
|
|
|
|
|
TestHelperVariadic(Test) - verify variadic template diagnostics helper
|
|
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2014, Hermann Vosseler <Ichthyostega@web.de>
|
2014-09-22 03:37:07 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2014-09-22 03:37:07 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2014-09-22 03:37:07 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file test-helper-variadic-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TestHelperVariadic_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2014-09-22 03:37:07 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // test fixture...
|
|
|
|
|
|
|
|
|
|
|
|
class Interface
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
Interface(){}
|
|
|
|
|
|
Interface(Interface const& o) { cout << "COPY.CT from "<<&o<<" !!!\n"; }
|
|
|
|
|
|
Interface(Interface const&& o) { cout << "MOVE.CT from "<<&o<<" !!!\n"; }
|
|
|
|
|
|
|
|
|
|
|
|
Interface& operator= (Interface const& o) { cout << "COPY= from "<<&o<<" !!!\n"; return *this; }
|
|
|
|
|
|
Interface& operator= (Interface const&& o) { cout << "MOVE= from "<<&o<<" !!!\n"; return *this; }
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~Interface() { }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Impl
|
|
|
|
|
|
: public Interface
|
|
|
|
|
|
{
|
|
|
|
|
|
string s_;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2014-09-23 03:36:51 +02:00
|
|
|
|
Impl(string ss ="ZOMG") : s_(ss) { }
|
2014-09-22 03:37:07 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline double
|
|
|
|
|
|
makeRvalue()
|
|
|
|
|
|
{
|
|
|
|
|
|
return atan2(0,-0.0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}//(End) test fixture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************//**
|
|
|
|
|
|
* @test document usage of the diagnostics helper for variadic templates.
|
|
|
|
|
|
* Errors in variadic template instantiations are sometimes hard to spot,
|
|
|
|
|
|
* due to the intricacies of template argument matching and the
|
|
|
|
|
|
* reference collapsing rules. Our diagnostics facility is itself a
|
|
|
|
|
|
* variadic function template, which, when supplied with an argument pack,
|
|
|
|
|
|
* will build a diagnostic string describing the arguments.
|
|
|
|
|
|
* @warning care has to be taken to pass the template arguments properly,
|
|
|
|
|
|
* since template argument matching might mess up the reference kind
|
|
|
|
|
|
* (rvalue, lvalue) of the passed types. Thus, either use std::forward,
|
|
|
|
|
|
* or spell out the template argument(s) explicitly on invocation
|
|
|
|
|
|
*
|
|
|
|
|
|
* @see showVariadicTypes()
|
|
|
|
|
|
* @see TestHelper_test
|
|
|
|
|
|
*/
|
|
|
|
|
|
class TestHelperVariadic_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
double d = makeRvalue();
|
2024-06-15 01:14:42 +02:00
|
|
|
|
double const& cr = d;
|
2014-09-23 03:36:51 +02:00
|
|
|
|
|
2014-09-22 03:37:07 +02:00
|
|
|
|
Impl obj;
|
|
|
|
|
|
Interface const& ref = obj;
|
2014-09-23 03:36:51 +02:00
|
|
|
|
|
2016-01-07 03:58:29 +01:00
|
|
|
|
cout << "--no-arg--\n" << showVariadicTypes() <<"\n";
|
2024-06-15 01:14:42 +02:00
|
|
|
|
cout << "--reference--\n" << showVariadicTypes(d) <<"\n";
|
|
|
|
|
|
cout << "--value--\n" << showVariadicTypes(makeRvalue()) <<"\n";
|
2014-09-22 03:37:07 +02:00
|
|
|
|
|
2024-06-15 01:14:42 +02:00
|
|
|
|
forwardFunction("two values", "foo", 42L); // displayed as char [4] const&, long &&
|
|
|
|
|
|
forwardFunction("references", d,cr,std::move(d)); // displayed as double&, double const&, double &&
|
2014-09-22 03:37:07 +02:00
|
|
|
|
|
2024-06-15 01:14:42 +02:00
|
|
|
|
forwardFunction("baseclass", ref); // displayed as Interface const&
|
2014-09-22 03:37:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-23 03:36:51 +02:00
|
|
|
|
/** this dummy simulates a typical variadic call
|
|
|
|
|
|
* which takes all arguments as '&&' for the purpose of "perfect forwarding"
|
|
|
|
|
|
*/
|
2014-09-22 03:37:07 +02:00
|
|
|
|
template<typename... ARGS>
|
|
|
|
|
|
void
|
2014-09-23 03:36:51 +02:00
|
|
|
|
forwardFunction (string id, ARGS&&... args)
|
2014-09-22 03:37:07 +02:00
|
|
|
|
{
|
|
|
|
|
|
cout << "--"<<id<<"--\n"
|
2024-06-15 01:14:42 +02:00
|
|
|
|
<< showVariadicTypes (std::forward<ARGS>(args)...)
|
2014-09-22 03:37:07 +02:00
|
|
|
|
<< "\n"
|
|
|
|
|
|
;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (TestHelperVariadic_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::test::test
|