generated from cpp-core/timer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
260984b
commit a8cf3b6
Showing
9 changed files
with
98 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (C) 2017, 2018, 2019, 2021, 2022, 2023 by Mark Melton | ||
// | ||
|
||
#pragma once | ||
#include <map> | ||
#include "builtin.h" | ||
#include "util.h" | ||
|
||
namespace core::lexical_cast_detail { | ||
|
||
template<class K, class V> | ||
struct lexical_cast_impl<std::map<K, V>> { | ||
std::map<K, V> convert(std::string_view s) const { | ||
auto [iter, end] = unwrap(s.begin(), s.end()); | ||
std::map<K, V> m; | ||
while (iter < end) { | ||
auto delim = find_first(iter, end, ','); | ||
m.emplace(lexical_cast<std::pair<K,V>>({iter, delim})); | ||
iter = delim + 1; | ||
} | ||
return m; | ||
} | ||
|
||
std::string to_string(const std::map<K, V>& m) const { | ||
std::string r = "{"; | ||
for (const auto& pair : m) { | ||
if (r.size() > 1) | ||
r += ","; | ||
r += lexical_to_string(pair); | ||
} | ||
r += "}"; | ||
return r; | ||
} | ||
}; | ||
|
||
}; // core::lexical_cast_detail | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (C) 2023 by Mark Melton | ||
// | ||
|
||
#include <iostream> | ||
#include "core/lexical_cast/string.h" | ||
#include "core/lexical_cast/pair.h" | ||
#include "core/lexical_cast/map.h" | ||
|
||
using namespace core; | ||
using std::cout, std::endl; | ||
|
||
int main(int argc, const char *argv[]) { | ||
auto text = R"({["a", 1], ["b", 2]})"; | ||
auto m = lexical_cast<std::map<std::string,int>>(text); | ||
cout << lexical_to_string(m) << endl; | ||
return 0; | ||
} |