// Copyright 2017 <Biagio Festa>
#include <iostream>
#include <string>
#include <utility>

using DateType = int;

class DateOrString {
 public:
  explicit DateOrString(std::string str)
      : m_is_a_string(true), m_string(std::move(str)) {}
  explicit DateOrString(DateType date) : m_date(std::move(date)) {}

  const std::string& get_string() const {
    if (m_is_a_string == false) {
      throw std::runtime_error("It does not keep a string type");
    }
    return m_string;
  }

  const DateType& get_date() const {
    if (m_is_a_string == true) {
      throw std::runtime_error("It does not keep a date type");
    }
    return m_date;
  }

  bool is_string() const noexcept { return m_is_a_string; }

 private:
  bool m_is_a_string = false;
  DateType m_date;
  std::string m_string;
};

DateOrString api_call(const std::string& selector) {
  if (selector.empty()) {
    return DateOrString{"This is a string"};
  }
  return DateOrString{DateType{}};
}

int main() {
  auto r1 = api_call("");
  auto r2 = api_call("s");

  std::cout << r1.get_string() << '\n';
  std::cout << r2.get_date() << '\n';

  return 0;
}
