From 785087aa43cf962855724b8fa5da393022204a14 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 29 Sep 2022 13:12:19 +0200 Subject: Add $find(, ), $find_index(, ) functions The $find() function returns true if the sequence contains the specified value. The $find_index() function returns the index of the first element in the sequence that is equal to the specified value or $size() if none is found. For string sequences, it's possible to request case- insensitive comparison with a flag. --- libbuild2/functions-name.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libbuild2/functions-name.cxx') diff --git a/libbuild2/functions-name.cxx b/libbuild2/functions-name.cxx index 43de039..9011cc0 100644 --- a/libbuild2/functions-name.cxx +++ b/libbuild2/functions-name.cxx @@ -330,6 +330,31 @@ namespace build2 return ns; }; + // $find(, ) + // + // Return true if the name sequence contains the specified name. + // + fn["find"] += [](names vs, names v) + { + //@@ TODO: shouldn't we do this in a pair-aware manner? + + return find (vs.begin (), vs.end (), + convert (move (v))) != vs.end (); + }; + + // $find_index(, ) + // + // Return the index of the first element in the name sequence that is + // equal to the specified name or $size() if none is found. + // + fn["find_index"] += [](names vs, names v) + { + //@@ TODO: shouldn't we do this in a pair-aware manner? + + auto i (find (vs.begin (), vs.end (), convert (move (v)))); + return i != vs.end () ? i - vs.begin () : vs.size (); + }; + // Functions that can be called only on real targets. // function_family ft (m, "target"); -- cgit v1.1