// This file is part of the lobster library
// Copyright: Andreas Raczek
// This file is published under the The Code Project Open License (CPOL)
// See the file "CPOL.html" for the full license governing this code.
#pragma once
namespace lobster {
namespace static_list {
template<
typename list,
typename list::value_type new_value_start,
typename list::value_type new_value_end = new_value_start
> struct find_insert_pos;
enum search_state {
pos_found,
search_continue,
search_error
};
template<
typename list,
typename list::value_type new_value_start,
typename list::value_type new_value_end,
search_state
> struct find_insert_pos_switch;
template<
typename list,
typename list::value_type new_value_start,
typename list::value_type new_value_end
> struct find_insert_pos_switch<
list,
new_value_start,
new_value_end,
pos_found
> {
static const int value = list::size;
};
template<
typename parent_list,
typename parent_list::value_type value_start,
typename parent_list::value_type value_end,
typename parent_list::value_type new_value_start,
typename parent_list::value_type new_value_end
> struct find_insert_pos_switch<
list_item<parent_list, value_start, value_end>,
new_value_start,
new_value_end,
search_continue
> {
static const int value = find_insert_pos<parent_list, new_value_start, new_value_end>::value;
};
template<
typename parent_list,
typename parent_list::value_type value_start,
typename parent_list::value_type value_end,
typename parent_list::value_type new_value_start,
typename parent_list::value_type new_value_end
> class find_insert_pos<
list_item<parent_list, value_start, value_end>,
new_value_start,
new_value_end
> {
typedef list_item<parent_list, value_start, value_end> this_list;
static_assert(is_ascending<this_list>::value, "find_insert_pos<...> list must be ascending");
static_assert(new_value_end >= new_value_start, "find_insert_pos<...> value parameters must be ascending");
const static search_state state_tag =
(new_value_start > value_end) ? pos_found :
(new_value_start <= value_end) && (new_value_end >= value_start) ? search_error :
search_continue;
static_assert(state_tag != search_error, "find_insert_pos<...> value parameters overlap with list item");
public:
static const int value = find_insert_pos_switch<this_list, new_value_start, new_value_end, state_tag>::value;
};
template<
typename value_type,
value_type new_value_start,
value_type new_value_end
> class find_insert_pos<
list_tail<value_type>,
new_value_start,
new_value_end
> {
void a1() {
static_assert(new_value_end >= new_value_start, "find_insert_pos<...> value parameters must be ascending");
}
public:
static const int value = 0;
};
}
}