Skip to content

Instantly share code, notes, and snippets.

@tannergooding
Created April 9, 2021 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tannergooding/6879d8e90b3b4a153f686fa956b040e1 to your computer and use it in GitHub Desktop.
Save tannergooding/6879d8e90b3b4a153f686fa956b040e1 to your computer and use it in GitHub Desktop.
#include "lib.h"
#include "common.h"
#include <iostream>
void thing()
{
auto lib_id1 = get_next_lib_id_int32();
auto lib_id2 = get_next_lib_id_size();
auto this_id1 = get_next_id<std::size_t>();
auto this_id2 = get_next_id<std::int32_t>();
std::cout <<
"lib id1: " << lib_id1 << "\n" <<
"lib id2: " << lib_id2 << "\n" <<
"this id1: " << this_id1 << "\n" <<
"this id2: " << this_id2 << "\n";
}
int main()
{
thing();
thing();
}
#include <cstddef>
#include <iostream>
std::size_t do_thing()
{
static std::size_t id;
std::cout << "whoa, do_thing has been called!\n";
return id++;
}
template <typename T>
extern std::size_t get_next_id()
{
static std::size_t id = do_thing();
return id;
}
#include "common.h"
#include "lib.h"
std::size_t get_next_lib_id_int32()
{
return get_next_id<std::int32_t>();
}
std::size_t get_next_lib_id_size()
{
return get_next_id<std::size_t>();
}
#include <cstddef>
std::size_t get_next_lib_id_int32();
std::size_t get_next_lib_id_size();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment