久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

boost::combine,基于范圍的和結(jié)構(gòu)化綁定

boost::combine, range-based for and structured bindings(boost::combine,基于范圍的和結(jié)構(gòu)化綁定)
本文介紹了boost::combine,基于范圍的和結(jié)構(gòu)化綁定的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

有沒有辦法讓 boost::combine 與結(jié)構(gòu)化綁定和基于范圍的 for 一起工作(這樣結(jié)構(gòu)綁定中的標(biāo)識符實際上指向容器的元素而不是嵌套的任何 boost::combine 在幕后使用)?以下(live example)無法編譯:

Is there a way to make boost::combine work with structured bindings and range-based for (so that identifiers in the structure binding actually point to containers' elements instead of nested tuples of whatever boost::combine uses under the hood)? The following (live example) fails to compile:

#include <boost/range/combine.hpp>
#include <iostream>

int main()
{
    std::vector<int> a{1,2,3};
    std::vector<int> b{2,3,4};

    for (auto [f, s] : boost::combine(a, b))
    {
        std::cout << f << ' ' << s << std::endl   
    }
}

推薦答案

真正的答案是使用 boost::tie 或抓取 range-v3 zip() 這實際上產(chǎn)生了一個 std::tuple.

The real answer is to use either boost::tie or grab the range-v3 zip() which actually yields a std::tuple.

僅用于教育目的的答案只是調(diào)整 boost::tuples::cons 的結(jié)構(gòu)化綁定機制.該類型已經(jīng)有一個 get() 與 ADL 一起工作并做正確的事情,所以我們需要做的就是提供 tuple_sizetuple_element(這最終真的很容易做到,因為 Boost 中已經(jīng)存在這些確切的特征):

The for educational purposes only answer is just to adapt the structured bindings machinery for boost::tuples::cons. That type already has a get() which works with ADL and does the right thing, so all we need to do is provide tuple_size and tuple_element (which ends up being really easy to do since these exact traits already exist in Boost):

namespace std {
    template <typename T, typename U>
    struct tuple_size<boost::tuples::cons<T, U>>
        : boost::tuples::length<boost::tuples::cons<T, U>>
    { };

    template <size_t I, typename T, typename U>
    struct tuple_element<I, boost::tuples::cons<T, U>>
        : boost::tuples::element<I, boost::tuples::cons<T, U>>
    { };
}

但實際上不要在實際代碼中這樣做,因為實際上只有類型作者應(yīng)該選擇加入這種事情.

But don't actually do that in real code, since really only the type author should opt-in to this kind of thing.

這將使結(jié)構(gòu)化綁定正常工作.

That'll make the structured binding just work.

這篇關(guān)于boost::combine,基于范圍的和結(jié)構(gòu)化綁定的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運算符的數(shù)學(xué)式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區(qū)別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達式中的變量聲明)
主站蜘蛛池模板: 欧美日韩欧美 | 亚洲高清在线免费观看 | 国产精品久久久久久吹潮 | 婷婷久久五月天 | 国产精品美女一区二区三区 | 免费一区二区三区 | 阿v视频在线观看 | 一区二区三区四区免费观看 | 国产午夜视频 | 中文字幕视频在线 | 免费观看一级视频 | 天天操天天拍 | 久久噜噜噜精品国产亚洲综合 | 精品欧美一区二区精品久久 | 久久人人网| 毛片a级 | 国产你懂的在线观看 | 久久综合一区 | 在线永久看片免费的视频 | 精品乱子伦一区二区三区 | www.伊人.com | 成人免费视频网站在线看 | 精品久久久久久久久久久久 | 91在线一区 | 中文字幕一二三 | 国产精品亚洲综合 | 国产精品一区二区不卡 | 男女在线网站 | 国产探花在线精品一区二区 | 国产一级片在线观看视频 | 一区二区三区视频在线观看 | 天天影视色综合 | 精品综合久久久 | 久久久久久a | 国内自拍真实伦在线观看 | 久久久久91 | 欧美综合色 | 天天操天天射综合网 | 精品伊人久久 | 亚洲精品一区在线观看 | jlzzjlzz国产精品久久 |