Skip to content

Instantly share code, notes, and snippets.

@dsh0005
Created June 14, 2021 19:05
Show Gist options
  • Save dsh0005/21e604b6478d653e94fc752282d97c88 to your computer and use it in GitHub Desktop.
Save dsh0005/21e604b6478d653e94fc752282d97c88 to your computer and use it in GitHub Desktop.
C++ vector ouroboros
#include <vector>
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
int main(int argc, char **argv){
(void)argc;
(void)argv;
std::vector<uint8_t> *b;
{
std::vector<uint8_t> a(sizeof(a));
b = new(a.data()) std::vector<uint8_t>();
std::swap(a, *b);
}
printf("b = %p\n", b);
printf("b->size() = %zu\n", b->size());
for(size_t i = 0; i < b->size(); i++){
printf("(*b)[%zu] = %" PRIx8 "\n", i, (*b)[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment