From 503d993447e8c8e72e80e35c154cb5d5cab1d84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= Date: Fri, 7 Aug 2020 10:32:58 +0200 Subject: [PATCH] Check the list is sorted during compilation. --- src/fileformat/file_format/pe/pe_dll_list.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/fileformat/file_format/pe/pe_dll_list.cpp b/src/fileformat/file_format/pe/pe_dll_list.cpp index f62cc91fc5..3093347dc7 100644 --- a/src/fileformat/file_format/pe/pe_dll_list.cpp +++ b/src/fileformat/file_format/pe/pe_dll_list.cpp @@ -4086,6 +4086,27 @@ constexpr static std::string_view defDllList[] = { "ztrace_maps.dll", }; + +// utility to check the list is really sorted (I can't use C++ algorithms here, as C++17 doesn't have constexpr version of these) +template constexpr bool isSorted(T && arr) { + auto first = std::begin(arr); + auto last = std::end(arr); + + if (first != last) { + auto next = first; + while (++next != last) { + if (std::less{}(*next, *first)) { + return false; + } + first = next; + } + } + return true; +} + +static_assert(isSorted(defDllList), "The List of DLLs must be sorted!"); + + namespace retdec { namespace fileformat {