Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a workaround to avoid a c++14 feature #1833

Merged
merged 1 commit into from
Jul 10, 2019

Conversation

ToruNiina
Copy link
Contributor

Hi,

Thank you for the amazing work. I'm one of the users of this great library.

Today I found that the latest version of this library includes a c++14 feature, lambda capture initializer. You can see it by the following minimum code.

// sample.cpp
#include <pybind11/pybind11.h>
#include <pybind11/functional.h>

PYBIND11_MODULE(example, /*m*/) {
}

and

$ g++-9 -std=c++11 -c -Wall -Wpedantic -Wextra sample.cpp
In file included from sample.cpp:2:
./include/pybind11/functional.h: In member function 'bool pybind11::detail::type_caster<std::function<_Res(_ArgTypes ...)> >::load(pybind11::handle, bool)':
./include/pybind11/functional.h:68:18: warning: lambda capture initializers only available with '-std=c++14' or '-std=gnu++14'
   68 |         value = [hfunc = func_handle(std::move(func))](Args... args) -> Return {
      |                  ^~~~~

As the name suggests, pybind11 requires only C++11 (at least now). Although most of the existing compilers can compile this c++14 extension, I think it is good to have a workaround to make it c++11 conformant.

So here I added a temporary function-object that behaves equivalently to the lambda expression.

@wjakob
Copy link
Member

wjakob commented Jul 10, 2019

Looks great, thank you!

@wjakob wjakob merged commit 74d335a into pybind:master Jul 10, 2019
@ToruNiina ToruNiina deleted the cxx14-init-capture branch July 10, 2019 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants