62ae965b0a
Fixes: system/core/base/include/android-base/expected.h: 186:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload] 195:22: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload] 611:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload] To quote Tom Cherry: I'm a bit confused at what's happening there. I think it's a bug in the linter itself. The general solution to that problem is a heavy dose of std::enable_if<> to hide that constructor when the 'U' parameter is the same class, but those constructors do have the necessarily std::enable_if<> lines. I think the problem is that the linter doesn't check that the macro _ENABLE_IF() expands into std::enable_if<>. Let me try explicitly putting the std::enable_if<> instead of the macro and check if it goes away. I expanded the macro but the linter doesn't still doesn't accept the format of `std::enable_if_t<(condition_here)>* = nullptr`. It does accept `typename Enable = std::enable_if_t<(condition_here), void>`, which is the syntax used on their example here: https://clang.llvm.org/extra/clang-tidy/checks/bugprone-forwarding-reference-overload.html. That latter syntax doesn't work for us. See the Notes section on https://en.cppreference.com/w/cpp/types/enable_if as a reference for why what we're doing is correct. Test: builds Bug: 153035880 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I493ff19208cc104f5f176a36ec23fbcb914388f7 Merged-In: I493ff19208cc104f5f176a36ec23fbcb914388f7 |
||
---|---|---|
.. | ||
include/android-base | ||
.clang-format | ||
abi_compatibility.cpp | ||
Android.bp | ||
chrono_utils.cpp | ||
chrono_utils_test.cpp | ||
cmsg.cpp | ||
cmsg_test.cpp | ||
CPPLINT.cfg | ||
endian_test.cpp | ||
errors_test.cpp | ||
errors_unix.cpp | ||
errors_windows.cpp | ||
expected_test.cpp | ||
file.cpp | ||
file_test.cpp | ||
format_benchmark.cpp | ||
liblog_symbols.cpp | ||
liblog_symbols.h | ||
logging.cpp | ||
logging_test.cpp | ||
macros_test.cpp | ||
mapped_file.cpp | ||
mapped_file_test.cpp | ||
no_destructor_test.cpp | ||
OWNERS | ||
parsebool.cpp | ||
parsebool_test.cpp | ||
parsedouble_test.cpp | ||
parseint_test.cpp | ||
parsenetaddress.cpp | ||
parsenetaddress_test.cpp | ||
process.cpp | ||
process_test.cpp | ||
properties.cpp | ||
properties_test.cpp | ||
README.md | ||
result_test.cpp | ||
scopeguard_test.cpp | ||
stringprintf.cpp | ||
stringprintf_test.cpp | ||
strings.cpp | ||
strings_test.cpp | ||
test_main.cpp | ||
test_utils.cpp | ||
test_utils_test.cpp | ||
threads.cpp | ||
utf8.cpp | ||
utf8_test.cpp |
libbase
Who is this library for?
This library is a collection of convenience functions to make common tasks easier and less error-prone.
In this context, "error-prone" covers both "hard to do correctly" and "hard to do with good performance", but as a general purpose library, libbase's primary focus is on making it easier to do things easily and correctly when a compromise has to be made between "simplest API" on the one hand and "fastest implementation" on the other. Though obviously the ideal is to have both.
Should my routine be added?
The intention is to cover the 80% use cases, not be all things to all users.
If you have a routine that's really useful in your project, congratulations. But that doesn't mean it should be here rather than just in your project.
The question for libbase is "should everyone be doing this?"/"does this make everyone's code cleaner/safer?". Historically we've considered the bar for inclusion to be "are there at least three unrelated projects that would be cleaned up by doing so".
If your routine is actually something from a future C++ standard (that isn't yet in libc++), or it's widely used in another library, that helps show that there's precedent. Being able to say "so-and-so has used this API for n years" is a good way to reduce concerns about API choices.
Any other restrictions?
Unlike most Android code, code in libbase has to build for Mac and Windows too.
Code here is also expected to have good test coverage.
By its nature, it's difficult to change libbase API. It's often best to start using your routine just in your project, and let it "graduate" after you're certain that the API is solid.