<commit_before>// Custom error code example : spoof game api functions
#include "the_game.h"
#include "renderer_error_codes.h"
#include "appengine_error_codes.h"
#include <system_error>
#include <memory>

namespace the_game
{
  std::error_code check_dimensions( int dim_min, int dim_max )
  {
    if ( dim_min < 3 )
    {
      return renderer_error::game_dimension_too_small;
    }
    if ( dim_max < dim_min )
    {
      return renderer_error::game_dimension_bad_range;
    }
    return {};
  }

  std::error_code appengine::take_renderer( std::unique_ptr<renderer> && rp )
  {
    auto ec{ check_dimensions(rp->min_dimension(), rp->max_dimension()) };
    if ( !ec )
    {
      rp_ = std::move(rp);
    }
    return ec;
  }

  std::error_code appengine::update_game_board()
  {
    return rp_ ? std::error_code{} : appengine_error::no_renderer;
  }

  int oops_renderer::min_dimension() const
  {
    return 5;
  }
  int oops_renderer::max_dimension() const
  {
    return 3;
  }

  int fine_renderer::min_dimension() const<commit_msg>Now zero initialise appengine_error{} in for true (good) case of appengine::update_game_board() to demonstrate the usage as its mentioned in the article text<commit_after>// Custom error code example : spoof game api functions
#include "the_game.h"
#include "renderer_error_codes.h"
#include "appengine_error_codes.h"
#include <system_error>
#include <memory>

namespace the_game
{
  std::error_code check_dimensions( int dim_min, int dim_max )
  {
    if ( dim_min < 3 )
    {
      return renderer_error::game_dimension_too_small;
    }
    if ( dim_max < dim_min )
    {
      return renderer_error::game_dimension_bad_range;
    }
    return {};
  }

  std::error_code appengine::take_renderer( std::unique_ptr<renderer> && rp )
  {
    auto ec{ check_dimensions(rp->min_dimension(), rp->max_dimension()) };
    if ( !ec )
    {
      rp_ = std::move(rp);
    }
    return ec;
  }

  std::error_code appengine::update_game_board()
  { // good case demonstrates zero-initialising enum class instance 
    return rp_ ? appengine_error{} : appengine_error::no_renderer;
  }

  int oops_renderer::min_dimension() const
  {
    return 5;
  }
  int oops_renderer::max_dimension() const
  {
    return 3;
  }

  int fine_renderer::min_dimension() const
{'fraction_non_alphanumeric': 0.11402359108781127, 'fraction_numerical': 0.002621231979030144, 'mean_word_length': 3.711934156378601, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6334925', 'n_tokens_mistral': 807, 'n_tokens_neox': 788, 'n_words': 169}