rozukke / mcpp

A library to interface with Minecraft using C++.
https://rozukke.github.io/mcpp/
Apache License 2.0
92 stars 14 forks source link

Fix for iterator type error in example pyramid.cpp #90

Closed erfansamandarian closed 5 days ago

erfansamandarian commented 5 days ago

Pyramid example doesn't work due to mcpp::HeightMap not supporting direct iteration over the heights stored in array.

See below.

rowan@kinson:~/Code/rmit/studio/examples$ mining pyramid_broken
===============================================
MINING: Compiling pyramid_broken.cc into pyramid_broken
===============================================
In file included from pyramid_broken.cc:1:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:1751:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/copy.h:15:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/min.h:14:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/min_element.h:55:3: error: static assertion failed due to requirement '__has_iterator_category_convertible_to<mcpp::HeightMap::Iterator, std::forward_iterator_tag, false>::value': std::min_element requires a ForwardIterator
  static_assert(__has_forward_iterator_category<_ForwardIterator>::value,
  ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/min_element.h:67:19: note: in instantiation of function template specialization 'std::min_element<mcpp::HeightMap::Iterator, std::__less<void, void>>' requested here
    return _VSTD::min_element(__first, __last, __less<>());
                  ^
pyramid_broken.cc:36:28: note: in instantiation of function template specialization 'std::min_element<mcpp::HeightMap::Iterator>' requested here
    int min_height = *std::min_element(heights.begin(), heights.end());
                           ^
1 error generated.
===============================================
MINING: Executing pyramid_broken
===============================================
mining:13: no such file or directory: ./pyramid_broken

Wrote rudimentary fix for the pyramid example, which extracts height values numbers into vector for std::min_element to work.

erfansamandarian commented 5 days ago

Nevermind, had old build, fixed in https://github.com/rozukke/mcpp/pull/86.