aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-04-04 02:03:48 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:27:32 +0300
commit545dc8ef97e90ffc1a5a62c59edffdc6e3b8e0b3 (patch)
treeff45c9a7011266df6afeab5a52d9d59d8028c545
parent9baac4cd7c98e5e8e3b96926ac300701dbdf0950 (diff)
support overloaded index access
-rwxr-xr-xsystem/include/emscripten/bind.h22
-rw-r--r--tests/embind/embind_test.cpp4
2 files changed, 8 insertions, 18 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index 81ee38e9..a0e825ad 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -472,14 +472,6 @@ namespace emscripten {
const noncopyable& operator=(const noncopyable&) = delete;
};
- template<typename T>
- struct ReturnType;
-
- template<typename RT, typename ClassType, typename... Args>
- struct ReturnType<RT (ClassType::*)(Args...)> {
- typedef RT type;
- };
-
template<typename ClassType, typename ElementType>
typename BindingType<ElementType>::WireType get_by_index(int index, ClassType& ptr) {
return BindingType<ElementType>::toWireType(ptr[index]);
@@ -553,11 +545,8 @@ namespace emscripten {
template<int Index>
value_tuple& element(index<Index>) {
using namespace internal;
- typedef
- typename std::remove_reference<
- typename ReturnType<decltype(&ClassType::operator[])>::type
- >::type
- ElementType;
+ ClassType* null = 0;
+ typedef typename std::remove_reference<decltype((*null)[Index])>::type ElementType;
_embind_register_tuple_element(
TypeID<ClassType>::get(),
TypeID<ElementType>::get(),
@@ -633,11 +622,8 @@ namespace emscripten {
template<int Index>
value_struct& field(const char* fieldName, index<Index>) {
using namespace internal;
- typedef
- typename std::remove_reference<
- typename ReturnType<decltype(&ClassType::operator[])>::type
- >::type
- ElementType;
+ ClassType* null = 0;
+ typedef typename std::remove_reference<decltype((*null)[Index])>::type ElementType;
_embind_register_struct_field(
TypeID<ClassType>::get(),
fieldName,
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index ea332f2d..1384406a 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -736,6 +736,10 @@ struct Vector {
return (&x)[i];
}
+ const float& operator[](int i) const {
+ return (&x)[i];
+ }
+
float getY() const {
return y;
}