<commit_before>require 'shellwords'
require 'tmpdir'

# Discovers support for C++11 features,
# and any required CXXFLAGS for such features.
class CXXCompiler
  CXX_COMPILER_FEATURES = <<-CODE
    template <typename T>
    struct check
    {
      static_assert(sizeof(int) <= sizeof(T), "not big enough");
    };

    typedef check<check<bool>> right_angle_brackets;

    int a;
    decltype(a) b;

    typedef check<int> check_type;
    check_type c;
    check_type&& cr = static_cast<check_type&&>(c);

    #ifdef __has_include
    #if __has_include(<type_traits>)
    #include <type_traits>
    #endif
    #endif
  CODE

  CXX_LIBRARY_FEATURES = <<-CODE
    #include <initializer_list>
    #include <unordered_map>
    #include <atomic>
    #include <thread>
  CODE

  # The environment variables (e.g. CXX, CXXFLAGS).
  def initialize(env)
    @env = env.dup
  end

  # True if support for C++11 was detected, false otherwise.
  def has_cxx11_compiler_support?
    !!std_flag
  end

  # True if support for C++11 libraries was detected, false otherwise.
  def has_cxx11_library_support?
    !!stdlib_flag
  end

  # The required std flag (e.g. '-std=c++11'),
  # empty string if unecessary given the current environment and/or compiler,
  # or nil in the case where the compiler has no support.
  def std_flag
    test_compiler_flags(@env)
    @std_flag
  end

  # The required stdlib flag (e.g. '-stdlib=libc++'),
  # empty string if unecessary given the current environment and/or compiler,
  # or nil in the case where the compiler has no support.
  def stdlib_flag
    test_compiler_flags(@env)
    @stdlib_flag
  end

  private

  # Detect any required flags.
  def test_compiler_flags(env)
    return if @tested<commit_msg>better error handling in C++ compiler detection<commit_after>require 'shellwords'
require 'tmpdir'

# Discovers support for C++11 features,
# and any required CXXFLAGS for such features.
class CXXCompiler
  CXX_COMPILER_FEATURES = <<-CODE
    template <typename T>
    struct check
    {
      static_assert(sizeof(int) <= sizeof(T), "not big enough");
    };

    typedef check<check<bool>> right_angle_brackets;

    int a;
    decltype(a) b;

    typedef check<int> check_type;
    check_type c;
    check_type&& cr = static_cast<check_type&&>(c);

    #ifdef __has_include
    #if __has_include(<type_traits>)
    #include <type_traits>
    #endif
    #endif
  CODE

  CXX_LIBRARY_FEATURES = <<-CODE
    #include <initializer_list>
    #include <unordered_map>
    #include <atomic>
    #include <thread>
  CODE

  # env: The environment variables (e.g. CXX, CXXFLAGS).
  def initialize(env)
    @env = env.dup
    @exist = system("command -v #{@env['CXX'].shellescape} >/dev/null 2>&1")
  end

  # True if the compiler is accessible on the $PATH.
  def exist?
    @exist
  end

  # True if support for C++11 was detected, false otherwise.
  def has_cxx11_compiler_support?
    !!std_flag
  end

  # True if support for C++11 libraries was detected, false otherwise.
  def has_cxx11_library_support?
    !!stdlib_flag
  end

  # The required std flag (e.g. '-std=c++11'),
  # empty string if unecessary given the current environment and/or compiler,
  # or nil in the case where the compiler has no support.
  def std_flag
    test_compiler_flags(@env)
    @std_flag
  end

  # The required stdlib flag (e.g. '-stdlib=libc++'),
  # empty string if unecessary given the current environment and/or compiler,
  # or nil in the case where the compiler has no support.
  def stdlib_flag
    test_compiler_flags(@env)
    @stdlib_flag
  end

  private

  # Detect any required flags.
  def test_compiler_flags(env)
    return if @tested || !exist?
{'fraction_non_alphanumeric': 0.09540636042402827, 'fraction_numerical': 0.007067137809187279, 'mean_word_length': 3.3861740166865317, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5977013', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1179, 'n_words': 380}