Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
4fac7daa
Commit
4fac7daa
authored
Dec 29, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup bit_cast
parent
3617c279
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
16 deletions
+12
-16
include/fmt/format.h
include/fmt/format.h
+12
-16
No files found.
include/fmt/format.h
View file @
4fac7daa
...
@@ -297,28 +297,23 @@ template <typename Streambuf> class formatbuf : public Streambuf {
...
@@ -297,28 +297,23 @@ template <typename Streambuf> class formatbuf : public Streambuf {
}
}
};
};
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't have
// Implementation of std::bit_cast for pre-C++20.
// undefined behavior (e.g. due to type aliasing).
template
<
typename
To
,
typename
From
>
// Example: uint64_t d = bit_cast<uint64_t>(2.718);
FMT_CONSTEXPR20
auto
bit_cast
(
const
From
&
from
)
->
To
{
template
<
typename
Dest
,
typename
Source
>
static_assert
(
sizeof
(
To
)
==
sizeof
(
From
),
"size mismatch"
);
FMT_CONSTEXPR20
auto
bit_cast
(
const
Source
&
source
)
->
Dest
{
static_assert
(
sizeof
(
Dest
)
==
sizeof
(
Source
),
"size mismatch"
);
#ifdef __cpp_lib_bit_cast
#ifdef __cpp_lib_bit_cast
if
(
is_constant_evaluated
())
{
if
(
is_constant_evaluated
())
return
std
::
bit_cast
<
To
>
(
from
);
return
std
::
bit_cast
<
Dest
>
(
source
);
}
#endif
#endif
Dest
dest
;
auto
to
=
To
()
;
std
::
memcpy
(
&
dest
,
&
source
,
sizeof
(
dest
));
std
::
memcpy
(
&
to
,
&
from
,
sizeof
(
to
));
return
dest
;
return
to
;
}
}
inline
auto
is_big_endian
()
->
bool
{
inline
auto
is_big_endian
()
->
bool
{
const
auto
u
=
1u
;
struct
bytes
{
struct
bytes
{
char
data
[
sizeof
(
u
)];
char
data
[
sizeof
(
int
)];
};
};
return
bit_cast
<
bytes
>
(
u
).
data
[
0
]
==
0
;
return
bit_cast
<
bytes
>
(
1
).
data
[
0
]
==
0
;
}
}
// A fallback implementation of uintptr_t for systems that lack it.
// A fallback implementation of uintptr_t for systems that lack it.
...
@@ -785,7 +780,8 @@ class basic_memory_buffer final : public detail::buffer<T> {
...
@@ -785,7 +780,8 @@ class basic_memory_buffer final : public detail::buffer<T> {
};
};
template
<
typename
T
,
size_t
SIZE
,
typename
Allocator
>
template
<
typename
T
,
size_t
SIZE
,
typename
Allocator
>
FMT_CONSTEXPR20
void
basic_memory_buffer
<
T
,
SIZE
,
Allocator
>::
grow
(
size_t
size
)
{
FMT_CONSTEXPR20
void
basic_memory_buffer
<
T
,
SIZE
,
Allocator
>::
grow
(
size_t
size
)
{
#ifdef FMT_FUZZ
#ifdef FMT_FUZZ
if
(
size
>
5000
)
throw
std
::
runtime_error
(
"fuzz mode - won't grow that much"
);
if
(
size
>
5000
)
throw
std
::
runtime_error
(
"fuzz mode - won't grow that much"
);
#endif
#endif
...
...
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