Skip to content

Instantly share code, notes, and snippets.

@ifknot
Last active September 5, 2020 19:01
Show Gist options
  • Save ifknot/9d1cbc0b8f1e8e069bb303f15050463a to your computer and use it in GitHub Desktop.
Save ifknot/9d1cbc0b8f1e8e069bb303f15050463a to your computer and use it in GitHub Desktop.
C++ heterogeneous container
#pragma once
#include <variant>
#include <string>
#include <vector>
#include <unordered_map>
#include <iostream>
#include <iomanip>
#include <sstream>
namespace R {
using basic_data_types = std::variant<char, double, int, std::string, std::tm>;
using variant_vector = std::vector<basic_data_types>;
/**
* As per R language definition the following are the characteristics of a data frame
*
* - The column names should be non-empty.
* - The row names should be unique.
* - The data stored in a data frame can be of numeric, factor or character type.
* - Each column should contain same number of data items.
*/
using data_frame = std::unordered_map<std::string, variant_vector>;
variant_vector as_dates(std::vector<std::string> dates);
}
std::ostream& operator<<(std::ostream& os, const std::tm& tm);
std::ostream& operator<<(std::ostream& os, const R::variant_vector& vv);
std::ostream& operator<<(std::ostream& os, const R::data_frame& df);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment