//********************************************************
// The following code example is taken from the book
//  C++23 - The Complete Guide
//  by Nicolai M. Josuttis (www.josuttis.com)
//  http://www.cppstd23.com
//
// The code is licensed under a
//  Creative Commons Attribution 4.0 International License
//  http://creativecommons.org/licenses/by/4.0/
//********************************************************


#include <array>
#include <stacktrace>
#include "printstacktrace.hpp"
 
bool find(const auto& coll, int idx)
{
  try {
    for (auto i = 0uz; i <= coll.size(); ++i) {
      return coll.at(idx);    
    }
  }
  catch (std::exception& e) {
    // create stacktrace:
    std::stacktrace st = std::stacktrace::current();

    // print the stacktrace:
    printStacktrace(st);
  }
  return false;
}

int callTest()
{
  std::array arr{47, 11};

  auto arrHas = [&arr] (int i) {
    return find(arr, 42);
  };

  return arrHas(42);
}

int main()
{
  callTest();
}

