Last active
December 20, 2015 10:49
-
-
Save gintenlabo/6118950 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <boost/utility/string_ref.hpp> | |
| #include <utility> | |
| #include <iostream> | |
| std::size_t all_length(std::initializer_list<boost::string_ref> ss) { | |
| std::size_t n = 0; | |
| for (auto const& s : ss) { | |
| n += s.size(); | |
| } | |
| return n; | |
| } | |
| template<class... Args, | |
| // SFINAE | |
| class = decltype( | |
| std::initializer_list<boost::string_ref>{std::declval<Args>()...}) | |
| > | |
| std::size_t all_length(Args&&... args) { | |
| return ::all_length({std::forward<Args>(args)...}); | |
| } | |
| int main() { | |
| std::string s = "hoge"; | |
| std::cout << all_length({}) << std::endl; | |
| std::cout << all_length({"hoge"}) << std::endl; | |
| std::cout << all_length() << std::endl; | |
| std::cout << all_length("hoge") << std::endl; | |
| std::cout << all_length("foo", s, "gonyogonyo") << std::endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment