0
#include <boost/range/adaptors.hpp>
#include <boost/assign.hpp>
#include <iostream>
using namespace boost::adaptors;
using namespace boost::assign;

template<int N>
struct factorial
{
    enum {
        value = N * factorial<N-1>::value
    };
};

template<>
struct factorial<0>
{
    enum {
        value = 1
    };

};

int main()
{
    typedef std::map<uint64_t, std::string> map_type;

    map_type const map_obj = {
        { 0x0000000000000401, "one"   },
        { 0x0000000000000002, "two"   },
        { 0x0000000000000003, "three" },
        { 0x0000000000000404, "four"  },
        { 0x0000000000000005, "five"  },
    };

    const int mask_value = 0x000000000000FF00;

    auto func = [](const map_type::value_type& p)
                    {
                        std::cout << " value_type.second: " << p.second << "\n";
                        return (p.first & mask_value) != 0;
                    };

    for(const auto&v : map_obj | filtered(func) | map_values)
    {
        std::cout << " Got: " << v <<"\n" ;
    }
    std::cout << " 5!: " << factorial<5>::value << "\n";
}

上面的示例代码用于在 Xcode 中编译,但在 Xcode 6.3 中,它无法在 main 函数的开头编译 map obj 的初始化列表。提升标头没有任何抱怨。有什么想法,为什么?

4

1 回答 1

0

哦,错误是链接时间错误,我的提升是使用 libc++ 而不是使用 libstdc++ 构建的。切换库有效。

于 2015-04-19T16:55:59.523 回答