Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
3c853c20
Commit
3c853c20
authored
4 years ago
by
Raphael Grimm
Browse files
Options
Downloads
Patches
Plain Diff
Add is_string_like
parent
3bf555c3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
SimoxUtility/CMakeLists.txt
+1
-0
1 addition, 0 deletions
SimoxUtility/CMakeLists.txt
SimoxUtility/meta/type_traits.h
+1
-0
1 addition, 0 deletions
SimoxUtility/meta/type_traits.h
SimoxUtility/meta/type_traits/is_string_like.h
+69
-0
69 additions, 0 deletions
SimoxUtility/meta/type_traits/is_string_like.h
with
71 additions
and
0 deletions
SimoxUtility/CMakeLists.txt
+
1
−
0
View file @
3c853c20
...
...
@@ -203,6 +203,7 @@ SET(INCLUDES
meta/type_traits/is_any_of.h
meta/type_traits/is_std_array.h
meta/type_traits/are_arithmetic.h
meta/type_traits/is_string_like.h
shapes/AxisAlignedBoundingBox.h
shapes/OrientedBoxBase.h
...
...
This diff is collapsed.
Click to expand it.
SimoxUtility/meta/type_traits.h
+
1
−
0
View file @
3c853c20
...
...
@@ -5,3 +5,4 @@
#include
"type_traits/are_arithmetic.h"
#include
"type_traits/is_any_of.h"
#include
"type_traits/is_std_array.h"
#include
"type_traits/is_string_like.h"
This diff is collapsed.
Click to expand it.
SimoxUtility/meta/type_traits/is_string_like.h
0 → 100644
+
69
−
0
View file @
3c853c20
#pragma once
#include
<string>
#include
<string_view>
#include
<type_traits>
#include
"is_any_of.h"
namespace
simox
::
meta
{
template
<
class
T
,
class
=
void
>
struct
is_string_like
:
std
::
false_type
{};
template
<
class
T
>
struct
is_string_like
<
T
,
std
::
enable_if_t
<
is_any_of_v
<
T
,
std
::
string
,
std
::
string_view
,
char
*
,
const
char
*
>
>>
:
std
::
true_type
{
static
constexpr
std
::
string_view
string_view
(
const
T
&
t
)
{
return
{
t
};
}
};
template
<
std
::
size_t
N
>
struct
is_string_like
<
char
[
N
],
void
>
:
std
::
true_type
{
static
constexpr
std
::
string_view
string_view
(
char
(
&
t
)[
N
])
{
return
{
t
,
N
};
}
};
template
<
std
::
size_t
N
>
struct
is_string_like
<
const
char
[
N
],
void
>
:
std
::
true_type
{
static
constexpr
std
::
string_view
string_view
(
const
char
(
&
t
)[
N
])
{
return
{
t
,
N
};
}
};
template
<
class
T
>
static
constexpr
bool
is_string_like_v
=
is_string_like
<
T
>::
value
;
template
<
class
T
,
class
R
=
void
>
using
enable_if_is_string_like
=
std
::
enable_if
<
is_string_like_v
<
T
>
,
R
>
;
template
<
class
T
,
class
R
=
void
>
using
enable_if_is_string_like_t
=
typename
enable_if_is_string_like
<
T
,
R
>::
type
;
}
namespace
simox
::
meta
::
detail
::
test
::
_is_string_like
{
template
<
class
T
>
constexpr
bool
test
(
const
T
&
)
{
return
is_string_like_v
<
T
>
;
}
static_assert
(
test
(
"qwer"
));
static_assert
(
is_string_like_v
<
std
::
string
>
);
static_assert
(
is_string_like_v
<
std
::
string_view
>
);
static_assert
(
!
is_string_like_v
<
int
>
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment