Turi Create
4.0
string_conversion_internals.hpp
1
/* Copyright © 2017 Apple Inc. All rights reserved.
2
*
3
* Use of this source code is governed by a BSD-3-clause license that can
4
* be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5
*/
6
#include <core/generics/gl_string.hpp>
7
8
#ifndef TURI_STRING_CONVERSION_INTERNALS_H_
9
#define TURI_STRING_CONVERSION_INTERNALS_H_
10
11
namespace
turi
{
namespace
gl_string_internal {
12
13
// as_string
14
template
<
typename
V>
15
GL_HOT_INLINE_FLATTEN
static
inline
16
gl_string as_string(
const
char
* fmt, V a) {
17
gl_string s;
18
s.resize(s.capacity());
19
size_t
available
= s.size();
20
while
(
true
) {
21
int
status = snprintf(&s[0], available, fmt, a);
22
if
( status >= 0 ) {
23
size_t
used =
static_cast<
size_t
>
(status);
24
if
( used <= available ) {
25
s.resize( used );
26
break
;
27
}
28
available = used;
// Assume this is advice of how much space we need.
29
}
else
{
30
available = available * 2 + 1;
31
}
32
33
s.resize(available);
34
}
35
return
s;
36
}
37
38
}}
39
40
#endif
/* _STRING_CONVERSION_INTERNALS_H_ */
turi
SKD.
Definition:
capi_initialization.hpp:11
GL_HOT_INLINE_FLATTEN
#define GL_HOT_INLINE_FLATTEN
Definition:
code_optimization.hpp:51
turi::memory_info::available
bool available()
Returns whether memory info reporting is available on this system (if memory_info was built with TCMa...
Definition:
memory_info.hpp:35
core
generics
string_conversion_internals.hpp
Generated by
1.8.13