Hi!
I’ve been trying to use std::function (which requires C++11) in an AOSP module (note: this is _not_ NDK code).
I am able to define and use lambda functions, so I know that C++11 is enabled, but I get an error saying that ‘function’ is not defined as part of the std namespace, although the compiler does not complain about not finding the <functional> header file.
If anyone’s used std::function with Android native code, I’d appreciate some advice on what I’m doing wrong.
I’m using stlport and I suspect it doesn't support std::function yet. I can’t get the GCC STL to work, so help with that is also appreciated.
My code and Android.mk are pasted below.
Thanks!
Neta
main.cpp
----------------------------------------------
#include <functional>
#include <iostream>
using namespace std;
void print_num(int i) {
std::cout << i << '\n';
}
// This does not compile ç
//std::function<void(int)> f_display = print_num;
template <typename T>
void use_f(T f) {
f(5);
}
int main(int argc, char** argv)
{
use_f( [](int i){ std::cout << i << "\n";} ); // ç using lambda function
}
Android.mk
----------------------------------------------
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.cpp
LOCAL_SHARED_LIBRARIES := libutils
LOCAL_CPPFLAGS += -std=c++11
LOCAL_MODULE := neta_test
# Including this will modify the include path
include external/stlport/libstlport.mk
include $(BUILD_EXECUTABLE)
--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.