@@ -32,56 +32,38 @@ device_filter::device_filter(const std::string &FilterString) {
3232
3333 // handle the optional 1st field of the filter, backend
3434 size_t Cursor = 0 ;
35- size_t ColonPos = FilterString.find (" :" , Cursor);
36- // check if the first entry matches with a known backend type
37- auto It = std::find_if (
38- std::begin (SyclBeMap), std::end (SyclBeMap),
39- [=, &Cursor](const std::pair<std::string, backend> &Element) {
40- size_t Found = FilterString.find (Element.first , Cursor);
41- if (Found != std::string::npos) {
42- Cursor = Found;
43- return true ;
44- }
45- return false ;
46- });
47- // if no match is found, set the backend type backend::all
48- // which actually means 'any backend' will be a match.
49- if (It == SyclBeMap.end ()) {
50- Backend = backend::all;
51- } else {
52- Backend = It->second ;
53- if (ColonPos != std::string::npos) {
35+ size_t ColonPos = 0 ;
36+ auto findElement = [&](auto &Element) {
37+ size_t Found = FilterString.find (Element.first , Cursor);
38+ if (Found == std::string::npos)
39+ return false ;
40+ Cursor = Found;
41+ return true ;
42+ };
43+ auto selectElement = [&](auto It, auto Map, auto EltIfNotFound) {
44+ if (It == Map.end ())
45+ return EltIfNotFound;
46+ ColonPos = FilterString.find (" :" , Cursor);
47+ if (ColonPos != std::string::npos)
5448 Cursor = ColonPos + 1 ;
55- } else {
49+ else
5650 Cursor = Cursor + It->first .size ();
57- }
58- }
51+ return It->second ;
52+ };
53+ // Check if the first entry matches with a known backend type
54+ auto It = std::find_if (
55+ std::begin (SyclBeMap), std::end (SyclBeMap), findElement);
56+ // If no match is found, set the backend type backend::all
57+ // which actually means 'any backend' will be a match.
58+ Backend = selectElement (It, SyclBeMap, backend::all);
5959
60- // handle the optional 2nd field of the filter, device type
61- // check if the 2nd entry matches with any known device type.
60+ // Handle the optional 2nd field of the filter - device type.
61+ // Check if the 2nd entry matches with any known device type.
6262 auto Iter = std::find_if (
63- std::begin (SyclDeviceTypeMap), std::end (SyclDeviceTypeMap),
64- [=, &Cursor](const std::pair<std::string, info::device_type> &Element) {
65- size_t Found = FilterString.find (Element.first , Cursor);
66- if (Found != std::string::npos) {
67- Cursor = Found;
68- return true ;
69- }
70- return false ;
71- });
72- // if no match is found, set device_type 'all'
63+ std::begin (SyclDeviceTypeMap), std::end (SyclDeviceTypeMap), findElement);
64+ // If no match is found, set device_type 'all',
7365 // which actually means 'any device_type' will be a match.
74- if (Iter == SyclDeviceTypeMap.end ()) {
75- DeviceType = info::device_type::all;
76- } else {
77- DeviceType = Iter->second ;
78- ColonPos = FilterString.find (" :" , Cursor);
79- if (ColonPos != std::string::npos) {
80- Cursor = ColonPos + 1 ;
81- } else {
82- Cursor = Cursor + Iter->first .size ();
83- }
84- }
66+ DeviceType = selectElement (Iter, SyclDeviceTypeMap, info::device_type::all);
8567
8668 // handle the optional 3rd field of the filter, device number
8769 // Try to convert the remaining string to an integer.
0 commit comments