resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmSubcommandTable.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "cmSubcommandTable.h"
4
5 #include <algorithm>
6
7 #include "cmExecutionStatus.h"
8 #include "cmStringAlgorithms.h"
9
10 cmSubcommandTable::cmSubcommandTable(std::initializer_list<InitElem> init)
11   : Impl(init.begin(), init.end())
12 {
13   std::sort(this->Impl.begin(), this->Impl.end(),
14             [](Elem const& left, Elem const& right) {
15               return left.first < right.first;
16             });
17 }
18
19 bool cmSubcommandTable::operator()(cm::string_view key,
20                                    std::vector<std::string> const& args,
21                                    cmExecutionStatus& status) const
22 {
23   auto const it = std::lower_bound(
24     this->Impl.begin(), this->Impl.end(), key,
25     [](Elem const& elem, cm::string_view k) { return elem.first < k; });
26   if (it != this->Impl.end() && it->first == key) {
27     return it->second(args, status);
28   }
29   status.SetError(cmStrCat("does not recognize sub-command ", key));
30   return false;
31 }