Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gauthier Quesnel
irritator
Commits
9ac9d152
Commit
9ac9d152
authored
Jun 03, 2021
by
Gauthier Quesnel
Browse files
core: add new generic functions
parent
b69bbb07
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/include/irritator/core.hpp
View file @
9ac9d152
...
...
@@ -226,6 +226,64 @@ is_defined(Identifier id) noexcept
return
id
!=
undefined
<
Identifier
>
();
}
/**
* @brief Enummeration to integral
*/
template
<
class
Enum
,
class
Integer
=
typename
std
::
underlying_type
<
Enum
>
::
type
>
constexpr
Integer
ordinal
(
Enum
e
)
noexcept
{
static_assert
(
std
::
is_enum
<
Enum
>::
value
,
"Identifier must be a enumeration"
);
return
static_cast
<
Integer
>
(
e
);
}
/**
* @brief Integral to enumeration
*/
template
<
class
Enum
,
class
Integer
=
typename
std
::
underlying_type
<
Enum
>
::
type
>
constexpr
Enum
enum_cast
(
Integer
i
)
noexcept
{
static_assert
(
std
::
is_enum
<
Enum
>::
value
,
"Identifier must be a enumeration"
);
return
static_cast
<
Enum
>
(
i
);
}
/**
* @brief returns an iterator to the result or end if not found
*
* Binary search function which returns an iterator to the result or end if
* not found using the lower_bound standard function.
*/
template
<
typename
Iterator
,
typename
T
>
Iterator
binary_find
(
Iterator
begin
,
Iterator
end
,
const
T
&
value
)
{
Iterator
i
=
std
::
lower_bound
(
begin
,
end
,
value
);
if
(
i
!=
end
&&
!
(
value
<
*
i
))
return
i
;
else
return
end
;
}
/**
* @brief returns an iterator to the result or end if not found
*
* Binary search function which returns an iterator to the result or end if
* not found using the lower_bound standard function.
*/
template
<
typename
Iterator
,
typename
T
,
typename
Compare
>
Iterator
binary_find
(
Iterator
begin
,
Iterator
end
,
const
T
&
value
,
Compare
comp
)
{
Iterator
i
=
std
::
lower_bound
(
begin
,
end
,
value
,
comp
);
if
(
i
!=
end
&&
!
comp
(
*
i
,
value
))
return
i
;
else
return
end
;
}
/*****************************************************************************
*
* Return status of many function
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment