4
새로운 컴파일러로 업그레이드하고 컴파일러 오류를 해결하는 동안 boost::fusion::for_each
에 전달 된 함수 객체에 연산자 const
이 필요하다는 것을 깨달았습니다. Boost에서std :: for_each와 다른 boost :: fusion :: for_each의 함수 객체
예 :
struct increment
{
template<typename T>
void operator()(T& t) const
{
++t;
}
};
...
vector<int,int> vec(1,2);
for_each(vec, increment());
이없는 변경 물론 있습니다. 나는 그것이 std::for_each
과 다르다는 것을 깨닫지 못했고, 연산자는 const
이 필요하지 않습니다.
struct increment
{
template<typename T>
void operator()(T& t) // no const here!!!
{
++t;
}
};
std::vector<int> numbers;
std::for_each(numbers.begin(), numbers.end(), increment());
const
이 필요한 이유가 있습니까? 분명히 그것을 바꿀 수는 없지만,이 두 가지가 다른 이유를 이해하고 싶습니다.
통찰력과 설명에 감사드립니다!
직관과 비슷하지만 의미가 있습니다 ;-) – Seb
주문에 정의되지 않은 부분이 있습니까? – murrekatt
@murrekatt 아니요, 아닙니다. 그러나 [문서] (http://www.boost.org/doc/libs/1_47_0/libs/fusion/doc/html/fusion/algorithm/iteration/functions/for_each.html)에는 엄격한 언급이 없습니다. 호출 순서. 그리고 관심있는 메일 링 스레드 (http://lists.boost.org/boost-users/2007/03/26355.php)가 있습니다. 주요 아이디어는 성능 최적화에 관한 것입니다. –