initial commit

[SVN r2349]
This commit is contained in:
Arkadiy Vertleyb committed 2004-11-10 03:35:59 +00:00
1 parent 143d3334e6
commit 6413c47d98
25 files changed
+1664

No files matched your search

+323
View File
@@ -0,0 +1,323 @@
// Copyright (C) 2004 Arkadiy Vertleyb
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
#pragma message("including typeof.hpp...")
#include <boost/typeof/typeof.hpp>
#pragma message("done")
#include <boost/noncopyable.hpp>
#include <boost/type_traits/is_same.hpp>
#pragma message("registering")
#include "stl/register.hpp"
#include "mpl/register.hpp"
#include "spirit/register.hpp"
#include "lambda/register.hpp"
#pragma message("done")
#include <cassert>
#include <iostream>
#include <vector>
#include <boost/lambda/lambda.hpp>
#include <boost/spirit.hpp>
#include <boost/mpl/vector.hpp>
#include "typeid.hpp"
using namespace std;
#pragma message("started")
double f_0()
{
cout << "functions with no params" << endl;
return 0;
}
double f_9(int, double, short, char*, bool, char, float, long, unsigned short)
{
cout << "functions with 9 params" << endl;
return 0;
}
void vf_0()
{
cout << "void functions with 0 params" << endl;
}
void vf_9(int, double, short, char*, bool, char, float, long, unsigned short)
{
cout << "void functions with 9 params" << endl;
}
struct x
{
int f_0() volatile
{
cout << "member functions with no params" << endl;
return 0;
}
int f_9(int, double, char, int, double, char, int, double, char)
{
cout << "member functions with 9 params" << endl;
return 0;
}
void vf_0()
{
cout << "void member functions with no params" << endl;
}
void vf_9(int, double, char, int, double, char, int, double, char)
{
cout << "void member functions with 9 params" << endl;
}
int cf_0() const volatile
{
cout << "const member functions with no params" << endl;
return 0;
}
int cf_9(int, double, char, int, double, char, int, double, char) const
{
cout << "const member functions with 9 params" << endl;
return 0;
}
void cvf_0() const
{
cout << "const void member functions with no params" << endl;
}
void cvf_9(int, double, char, int, double, char, int, double, char) const
{
cout << "const void member functions with 9 params" << endl;
}
static void sf_0()
{
cout << "static member function" << endl;
}
std::vector<int> m_v;
};
struct noncop : boost::noncopyable
{};
const noncop& foo_nc()
{
static noncop nc;
return nc;
}
template<class T, char c, unsigned short us,
int i, unsigned long ul, bool b1, bool b2, unsigned u> struct with_integrals
{};
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
BOOST_TYPEOF_REGISTER_TYPE(x)
BOOST_TYPEOF_REGISTER_TEMPLATE_X(with_integrals,
(class)
(char)
(unsigned short)
(int)
(unsigned long)
(bool)
(bool)
(unsigned)
);
BOOST_TYPEOF_REGISTER_TYPE(noncop)
main()
{
//#pragma message("integral...")
// {
// with_integrals<int, 5, 4, 3, 2, true, false, 5> expr;
// BOOST_AUTO(v, expr);
// v;
// with_integrals<int, 1, 1, 0, ULONG_MAX, false, true, 0> expr1;
// BOOST_AUTO(v1, expr1);
// v1;
// }
#pragma message("Noncopyable...")
{
//BOOST_AUTO(v, foo_nc());
BOOST_AUTO(const& v, foo_nc());
}
#pragma message("Lvalue preserving...")
{
int n;
const int cn = 0;
int& rn = n;
const int& rcn = cn;
int f();
//const int cf();
int& rf();
const int& rcf();
cout << type_id<BOOST_LVALUE_TYPEOF(n)>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(cn)>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(rn)>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(rcn)>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(f())>::name() << endl;
//cout << type_id<BOOST_LVALUE_TYPEOF(cf())>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(rf())>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(rcf())>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(21)>::name() << endl;
cout << type_id<BOOST_LVALUE_TYPEOF(int(21))>::name() << endl;
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(n), int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(cn), const int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rn), int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rcn), const int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(f()), int>::value));
//BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(cf()), const int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rf()), int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rcf()), const int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(21), int>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(int(21)), int>::value));
}
#pragma message("compiling Lambda example...")
{
using namespace boost::lambda;
BOOST_AUTO(fun, _1 > 15 && _2 < 20);
int n = 19;
assert(fun(n, n));
std::cout << typeid(fun).name() << std::endl;
}
#pragma message("compiling Spirit example...")
{
// spirit example
using namespace boost::spirit;
using namespace boost::lambda;
using namespace std;
vector<double> v;
BOOST_AUTO(parser,
(real_p[push_back_a(v)] >> *(',' >> real_p[push_back_a(v)]))
);
parse("3.14159, 2.71828", parser, space_p);
for_each(v.begin(), v.end(), cout << _1 << ' ');
cout << endl;
}
#pragma message("compiling another Spirit example...")
{
// more spirit...
using namespace boost::spirit;
BOOST_AUTO(
skipper,
( space_p
| "//" >> *(anychar_p - '\n') >> '\n'
| "/*" >> *(anychar_p - "*/") >> "*/"
)
);
bool success = parse(
"/*this is a comment*/\n//this is a c++ comment\n\n",
*skipper).full;
assert(success);
}
#pragma message("compiling Modifiers example...")
{
//modifiers
using namespace std;
using namespace boost;
// top-level pointers are preserved...
mpl::vector3<const int* const, const int[20], const int&>* foo();
cout << typeid(BOOST_TYPEOF(foo())).name() << endl;
// ... but top-level refs are not :(
mpl::vector2<const int* const, const int&>& bar();
cout << typeid(BOOST_TYPEOF(bar())).name() << endl;
mpl::vector1<int[5]> vi;
cout << "int[5]" << endl;
cout << typeid(BOOST_TYPEOF(vi)).name() << endl;
mpl::vector1<const int[5]> vci;
cout << "const int[5]" << endl;
cout << typeid(BOOST_TYPEOF(vci)).name() << endl;
}
#pragma message("compiling functions example...")
{
BOOST_AUTO(p0, &f_0);
(*p0)();
BOOST_AUTO(p9, &f_9);
(*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0);
}
#pragma message("compiling void functions example...")
{
BOOST_AUTO(p0, &vf_0);
(*p0)();
BOOST_AUTO(p9, &vf_9);
(*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0);
}
#pragma message("compiling member functions example...")
{
x xx;
BOOST_AUTO(p0, &x::f_0);
(xx.*p0)();
BOOST_AUTO(p9, &x::f_9);
(xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0);
}
#pragma message("compiling void member functions example...")
{
x xx;
BOOST_AUTO(p0, &x::vf_0);
(xx.*p0)();
BOOST_AUTO(p9, &x::vf_9);
(xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0);
}
#pragma message("compiling const member functions example...")
{
x xx;
BOOST_AUTO(p0, &x::cf_0);
(xx.*p0)();
BOOST_AUTO(p9, &x::cf_9);
(xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0);
}
#pragma message("compiling const void member functions example...")
{
x xx;
BOOST_AUTO(p0, &x::cvf_0);
(xx.*p0)();
BOOST_AUTO(p9, &x::cvf_9);
(xx.*p9)(0, 0, 0, 0, 0, 0, 0, 0, 0);
}
#pragma message("compiling static member functions example...")
{
BOOST_AUTO(p0, &x::sf_0);
(*p0)();
}
#pragma message("pointers to data members...")
{
BOOST_AUTO(p, &x::m_v);
x xx;
(xx.*p).push_back(1);
}
#pragma message("ODR")
void odr_test1();
void odr_test2();
odr_test1();
odr_test2();
#pragma message("done!")
}
+48
View File
@@ -0,0 +1,48 @@
// Copyright (C) 2004 Arkadiy Vertleyb
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
#ifndef ODR_HPP_INCLUDED
#define ODR_HPP_INCLUDED
#include <boost/typeof/typeof.hpp>
void odr_test1();
void odr_test2();
// trying to cause ODR violation in a class template
template<class T, class U>
class sum_t
{
public:
typedef BOOST_TYPEOF_TPL(T() + U()) result_type;
sum_t(const T& t, const U& u)
: m_sum(t + u)
{}
BOOST_TYPEOF_TPL(T() + U()) operator()()
{
BOOST_AUTO_TPL(result, m_sum);
return result;
}
private:
BOOST_TYPEOF_TPL(T() + U()) m_sum;
};
template<class T, class U>
sum_t<T, U> make_sum(const T& t, const U& u)
{
return sum_t<T, U>(t, u);
}
// trying to cause ODR violation in a function template
template<class T, class U>
typename sum_t<T, U>::result_type sum(const T& t, const U& u)
{
BOOST_AUTO_TPL(result, t + u);
return result;
}
#endif//ODR_HPP_INCLUDED
+18
View File
@@ -0,0 +1,18 @@
// Copyright (C) 2004 Arkadiy Vertleyb
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
#include <iostream>
#include "odr.hpp"
using namespace std;
void odr_test1()
{
char i = 5;
double d = 3.14;
cout << sum(d, i) << endl;
cout << sum(i, d) << endl;
cout << make_sum(d, i)() << endl;
cout << make_sum(i, d)() << endl;
}
+18
View File
@@ -0,0 +1,18 @@
// Copyright (C) 2004 Arkadiy Vertleyb
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
#include <iostream>
#include "odr.hpp"
using namespace std;
void odr_test2()
{
char i = 5;
double d = 3.14;
cout << sum(d, i) << endl;
cout << sum(i, d) << endl;
cout << make_sum(d, i)() << endl;
cout << make_sum(i, d)() << endl;
}
+33
View File
@@ -0,0 +1,33 @@
// Copyright (C) 2004 Arkadiy Vertleyb
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
#ifndef TYPEID_HPP_INCLUDED
#define TYPEID_HPP_INCLUDED
#include <string>
template<class T> struct type_id
{
static std::string name()
{
return typeid(T).name();
}
};
template<class T> struct type_id<T&>
{
static std::string name()
{
return type_id<T>::name() + "&";
}
};
template<class T> struct type_id<const T>
{
static std::string name()
{
return std::string("const ") + type_id<T>::name();
}
};
#endif//TYPEID_HPP_INCLUDED
+21
View File
@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "typeof", "typeof.vcproj", "{5C140C9B-1EF9-483D-92CB-86A1108AA7BF}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Debug.ActiveCfg = Debug|Win32
{5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Debug.Build.0 = Debug|Win32
{5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Release.ActiveCfg = Release|Win32
{5C140C9B-1EF9-483D-92CB-86A1108AA7BF}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal
+217
View File
@@ -0,0 +1,217 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="typeof"
ProjectGUID="{5C140C9B-1EF9-483D-92CB-86A1108AA7BF}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/typeof.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/typeof.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="C:\boost\boost_1_32_0;../../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/typeof.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\main.cpp">
</File>
<File
RelativePath=".\odr1.cpp">
</File>
<File
RelativePath=".\odr2.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath="..\..\..\..\boost\typeof\compliant\concatenate.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\config.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\encode_decode.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\increment_registration_group.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\int_encoding.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\limit_size.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\lvalue_typeof.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\modifiers.hpp">
</File>
<File
RelativePath=".\odr.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\pointers_data_members.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\register_functions.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\register_functions_iterate.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\register_fundamental.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\register_mem_functions.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\template_encoding.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\type_encoding.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\typeof.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\typeof\compliant\typeof_impl.hpp">
</File>
</Filter>
<Filter
Name="spirit"
Filter="">
<File
RelativePath=".\spirit\register.hpp">
</File>
</Filter>
<Filter
Name="lambda"
Filter="">
<File
RelativePath=".\lambda\register.hpp">
</File>
</Filter>
<Filter
Name="stl"
Filter="">
<File
RelativePath=".\stl\register.hpp">
</File>
</Filter>
<Filter
Name="mpl"
Filter="">
<File
RelativePath=".\mpl\register.hpp">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
+2
View File
@@ -0,0 +1,2 @@
g++ -IC:\boost\boost_1_32_0 -I..\..\..\.. -D BOOST_TYPEOF_FORCE_EMULATION -D BOOST_TYPEOF_LIMIT_SIZE=50 -D BOOST_MPL_LIMIT_VECTOR_SIZE=50 odr1.cpp odr2.cpp main.cpp
g++ -IC:\boost\boost_1_32_0 -I..\..\..\.. odr1.cpp odr2.cpp main.cpp