Skip to content

Commit

Permalink
Update operators to use results of expressions as the return type.
Browse files Browse the repository at this point in the history
configure detects the presence of decltype, typeof, __typeof__ or boost
to facilitate this, and falls back on a simple implementation for obvious
numeric types if none of these are present.

The type deduction has to go via classes such as:

	template<class L, class R> struct AddType
	{
		typedef TOON_TYPEOF((L()+R())) type;
	};

Because using constructs such as:

// Addition Vector + Vector
template<int Size, typename P1, typename P2, typename B1, typename B2>
Vector<Size, TOON_TYPEOF(P1()+P2())> operator+(const Vector<Size, P1, B1>& v1, const Vector<Size, P2, B2>& v2)
{
	typedef TOON_TYPEOF(P1()+P2()) restype;
	return Vector<Size,restype>(v1, v2, Operator<Internal::Add<restype> >());
}

causes the following error:

TooN/test/test2.cc:15: sorry, unimplemented: mangling typeof, use decltype instead

or

TooN/test/test2.cc:15: sorry, unimplemented: call_expr cannot be mangled due to a defect in the C++ ABI

or

TooN/test/test2.cc:16: internal compiler error: in write_type, at cp/mangle.c:1649
Please submit a full bug report,
with preprocessed source if appropriate.
  • Loading branch information
edrosten committed Feb 17, 2009
1 parent b28dce7 commit 2947783
Show file tree
Hide file tree
Showing 8 changed files with 1,102 additions and 42 deletions.
3 changes: 3 additions & 0 deletions Makefile.in
Expand Up @@ -17,6 +17,9 @@ install:
internal/make_vector.hh: make_make_vector.awk
awk -f make_make_vector.awk > $@

internal/builtin_typeof.h:make_typeof.awk
awk -f make_typeof.awk > $@

clean:
rm -rf html

Expand Down
3 changes: 3 additions & 0 deletions TooN.h
Expand Up @@ -3,6 +3,9 @@
#define TOON_INCLUDE_TOON_H
#include <iostream>
#include <cstdlib>
#include <TooN/internal/config.hh>
#include <TooN/internal/typeof.hh>

namespace TooN
{

Expand Down

0 comments on commit 2947783

Please sign in to comment.