Add a function that returns a MaxSizedArray.
This way you can use it to construct ie: a boost::string_ref or just take the buffer and use it as a c-style string.
This commit is contained in:
parent
1696acae44
commit
91dca8810a
2 changed files with 25 additions and 0 deletions
|
@ -256,6 +256,11 @@ namespace dhandy {
|
|||
return dhandy::implem::lexical_cast<Tag>::template convert<T, F>(parFrom);
|
||||
}
|
||||
|
||||
template <typename C, template <typename> class Tag=tags::dec, typename F=void>
|
||||
inline auto int_to_string_ary (const F& parFrom) -> MaxSizedArray<C, Tag<F>::count_digits_bt(sprout::numeric_limits<F>::max())> {
|
||||
return dhandy::lexical_cast<MaxSizedArray<C, Tag<F>::count_digits_bt(sprout::numeric_limits<F>::max())>, Tag, F>(parFrom);
|
||||
}
|
||||
|
||||
namespace customize {
|
||||
template<>
|
||||
struct index_to_char<char> {
|
||||
|
@ -299,6 +304,12 @@ namespace dhandy {
|
|||
return std::string(parIn.begin(), parIn.end());
|
||||
}
|
||||
};
|
||||
template<typename C, std::size_t S>
|
||||
struct array_to_t<C, S, MaxSizedArray<C, S>> {
|
||||
static MaxSizedArray<C, S> make (MaxSizedArray<C, S>&& parIn) {
|
||||
return parIn;
|
||||
}
|
||||
};
|
||||
} //namespace customize
|
||||
} //namespace dhandy
|
||||
#endif
|
||||
|
|
|
@ -81,6 +81,7 @@ TEST_CASE ("Check int to string conversions", "[i2s][lexical_cast]") {
|
|||
using std::string;
|
||||
using dhandy::lexical_cast;
|
||||
using dhandy::tags::bin;
|
||||
using dhandy::int_to_string_ary;
|
||||
|
||||
CHECK(lexical_cast<string>(1) == "1");
|
||||
CHECK(lexical_cast<string>(static_cast<uint16_t>(0xFFFF)) == "65535");
|
||||
|
@ -90,4 +91,17 @@ TEST_CASE ("Check int to string conversions", "[i2s][lexical_cast]") {
|
|||
CHECK((lexical_cast<string, bin>(static_cast<int16_t>(0x7FFF)) == "111111111111111"));
|
||||
CHECK((lexical_cast<string, bin>(static_cast<long>(0x0)) == "0"));
|
||||
CHECK((lexical_cast<string, bin>(static_cast<long>(0x1)) == "1"));
|
||||
|
||||
{
|
||||
auto fixed = int_to_string_ary<char>(1234);
|
||||
std::string str = lexical_cast<std::string>(1234);
|
||||
REQUIRE(fixed.size() == str.size());
|
||||
CHECK(std::equal(fixed.begin(), fixed.end(), str.begin()));
|
||||
}
|
||||
{
|
||||
auto fixed = int_to_string_ary<char>(-1234);
|
||||
std::string str = lexical_cast<std::string>(-1234);
|
||||
REQUIRE(fixed.size() == str.size());
|
||||
CHECK(std::equal(fixed.begin(), fixed.end(), str.begin()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue