Android C++ using std::max template compilation failed

Viewed 18

I write following code using std::max:

size_t block_size = 1024;
size_t step_size = 512;
size_t final_steps = std::max(1, (block_size / step_size) - 1);

And compilation fails with following error:

/app/src/main/cpp/src/main.cpp:151:36: error: no matching function for call to 'max'
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2605:1: note: candidate template ignored: deduced conflicting types for parameter '_Tp' ('int' vs. 'unsigned long')
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2616:1: note: candidate template ignored: could not match 'initializer_list<type-parameter-0-0>' against 'int'
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2596:1: note: candidate function template not viable: requires 3 arguments, but 2 were provided
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2625:1: note: candidate function template not viable: requires single argument '__t', but 2 arguments were provided

I tried 1u literal instead of 1, but then I received similar error:

/app/src/main/cpp/src/main.cpp:151:36: error: no matching function for call to 'max'
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2605:1: note: candidate template ignored: deduced conflicting types for parameter '_Tp' ('unsigned int' vs. 'unsigned long')
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2616:1: note: candidate template ignored: could not match 'initializer_list<type-parameter-0-0>' against 'unsigned int'
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2625:1: note: candidate function template not viable: requires single argument '__t', but 2 arguments were provided
/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:2596:1: note: candidate function template not viable: requires 3 arguments, but 2 were provided

What is the best solution to fix that?

0 Answers
Related