Skip to content

Instantly share code, notes, and snippets.

@ridiculousfish
Created November 18, 2018 08:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ridiculousfish/c9c2a0509ec8de488d0aba7c30cff056 to your computer and use it in GitHub Desktop.
#include <memory>
#include <string>
struct CharList {
char c;
std::unique_ptr<CharList> next;
explicit CharList(char c) : c(c) {}
};
CharList make_list(const std::string &s) {
CharList res{'a'};
auto *tail = &res.next;
for (char c : s) {
*tail = std::make_unique<CharList>(c);
tail = &(*tail)->next;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment