boost :: hana tuple解压缩可变参数模板实例化

时间:2016-06-24 07:50:52

标签: c++ boost c++14 boost-hana

this question相关我想知道这样的事情是否可以使用boost :: hana以直截了当的方式实现:

#include <boost/hana.hpp>
#include <boost/hana/unpack.hpp>

namespace hana = boost::hana;

template<typename ... T>
struct A {};

int main() {

  auto my_tuple = hana::tuple_t<int, double, float>;

  // Is there any way to unpack my_tuple as template arguments for A?
  // Something like
  using MyStruct = A<hana::unpack_types(my_tuple)...>;

  static_assert(std::is_same<MyStruct, A<int, double, float>>::value, "Ooops!");
}

3 个答案:

答案 0 :(得分:8)

使用template_A提升为元功能,然后拨打unpack

using MyStruct = decltype(hana::unpack(my_tuple, hana::template_<A>))::type;

Example

答案 1 :(得分:1)

你可以自己做:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Path;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;

/**
 * @see http://stackoverflow.com/a/38008678/230513
 */
public class Test extends Application {

    private final Image IMAGE = new Image("http://i.imgur.com/kxXhIH1.jpg");

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Test");
        int w = (int) (IMAGE.getWidth());
        int h = (int) (IMAGE.getHeight());
        ImageView view = new ImageView(IMAGE);
        Rectangle r = new Rectangle(w, h);
        Ellipse e = new Ellipse(w / 2, h / 2, w / 2, h / 2);
        Shape matte = Path.subtract(r, e);
        matte.setFill(Color.SIENNA);
        StackPane root = new StackPane();
        root.getChildren().addAll(view, matte);
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

答案 2 :(得分:0)

如果你关心的只是获得正确的类型,那么这是一种简单的方法:

SQL Server Management Studio 10.5