如何在Cloudfront上的静态托管网站上为子目录设置默认根对象?具体来说,我想www.example.com/subdir/index.html在用户要求时提供服务www.example.com/subdir.注意,这是用于提供在S3存储桶中保存的静态网站.此外,我想使用原始访问标识将对S3存储桶的访问限制为仅限Cloudfront.
现在,我知道的Cloudfront作品不同于S3和Amazon规定明确:
CloudFront默认根对象的行为与Amazon S3索引文档的行为不同.将Amazon S3存储桶配置为网站并指定索引文档时,即使用户请求存储桶中的子目录,Amazon S3也会返回索引文档.(索引文档的副本必须出现在每个子目录中.)有关将Amazon S3存储桶配置为网站和索引文档的更多信息,请参阅Amazon Simple Storage Service开发人员指南中的Amazon S3上的主机网站章节.
因此,即使Cloudfront允许我们指定默认的根对象,这只适用于www.example.com而不适用于www.example.com/subdir.为了解决这个难题,我们可以将原始域名更改为指向S3给出的网站端点.这很好用,可以统一指定根对象.不幸的是,这似乎与原始访问标识不相容.具体来说,以上链接指出:
切换到编辑模式:
Web分布 - 单击"起源"选项卡,单击要编辑的原点,然后单击"编辑".您只能为Origin Type为S3 Origin的原点创建原始访问标识.
基本上,为了设置正确的默认根对象,我们使用S3网站端点而不是网站存储桶本身.这与使用原始访问标识不兼容.因此,我的问题归结为两者
是否可以为Cloudfront上的静态托管网站的所有子目录指定默认根对象?
是否可以为从Cloudfront提供的内容设置原始访问标识,其中源是S3网站端点而不是S3存储桶?
有没有一种方法可以std::tie一次性使用和创建一个新变量?换句话说,如果函数返回a std::tuple并且我们希望最终将结果分解为单个组件,那么有没有办法在不事先定义变量的情况下执行这些赋值?
例如,请考虑以下代码:
#include <tuple>
struct Foo {
Foo(int) {}
};
struct Bar{};
std::tuple <Foo,Bar> example() {
return std::make_tuple(Foo(1),Bar());
}
int main() {
auto bar = Bar {};
// Without std::tie
{
auto foo_bar = example();
auto foo = std::get<0>(std::move(foo_bar));
bar = std::get<1>(std::move(foo_bar));
}
// With std::tie
#if 0
{
// Error: no default constructor
Foo foo;
std::tie(foo,bar) = example();
}
#endif
}
Run Code Online (Sandbox Code Playgroud)
基本上,该函数example返回一个元组.我们已经有了一个Bar我们想要分配的变量类型,但我们需要一个新的类型变量Foo.没有std::tie,我们不需要创建一个虚拟实例Foo,但代码要求我们将所有内容放入std::tuple第一个然后除以它.有了std::tie …
我正在玩一个用C++重载lambdas的技巧.特别:
// For std::function
#include <functional>
// For std::string
#include <string>
// For std::cout
#include <iostream>
template <class... F>
struct overload : F... {
overload(F... f) : F(f)... {}
};
template <class... F>
auto make_overload(F... f) {
return overload<F...>(f...);
}
int main() {
std::function <int(int,int)> f = [](int x,int y) {
return x+y;
};
std::function <double(double,double)> g = [](double x,double y) {
return x+y;
};
std::function <std::string(std::string,std::string)> h = [](std::string x,std::string y) {
return x+y;
};
auto fgh = make_overload(f,g,h); …Run Code Online (Sandbox Code Playgroud) 为什么在const对象上调用std :: move会在传递给另一个对象时调用复制构造函数?具体来说,代码
#include <iostream>
struct Foo {
Foo() = default;
Foo(Foo && x) { std::cout << "Move" << std::endl; }
Foo(Foo const & x) = delete;
};
int main() {
Foo const x; Foo y(std::move(x));
}
Run Code Online (Sandbox Code Playgroud)
无法使用消息进行编译:
g++ -std=c++14 test07.cpp -o test07
test07.cpp: In function 'int main()':
test07.cpp:10:36: error: use of deleted function 'Foo::Foo(const Foo&)'
Foo const x; Foo y(std::move(x));
^
test07.cpp:6:5: note: declared here
Foo(Foo const & x) = delete;
^
Makefile:2: recipe for target 'all' …Run Code Online (Sandbox Code Playgroud) 在以下代码中:
#include <memory>
#include <iostream>
void mydeallocator(int * x) {
std::cerr << "Freeing memory" << std::endl;
delete x;
}
struct Foo {
std::unique_ptr <int,std::function <void(int*)>> x;
Foo(bool fail) : x(new int(1),mydeallocator) {
if(fail)
throw std::runtime_error("We fail here");
}
};
int main() {
{auto foo1 = Foo(false);}
{auto foo2 = Foo(true);}
}
Run Code Online (Sandbox Code Playgroud)
看来,Foo(true)调用时内存没有被正确释放.也就是说,当我们编译并运行该程序时,我们得到了结果:
Freeing memory
terminate called after throwing an instance of 'std::runtime_error'
what(): We fail here
Aborted
Run Code Online (Sandbox Code Playgroud)
我相信该消息Freeing memory应该被调用两次.基本上,根据这个问题和这里和这里的ISO C++人员,我的理解是堆栈应该在构造函数上展开, …
以下代码编译并运行正常:
#include <memory>
struct MyTree {
std::shared_ptr <MyTree> left;
std::shared_ptr <MyTree> right;
int val;
MyTree(
std::shared_ptr <MyTree> left_,
std::shared_ptr <MyTree> right_,
int val_
) : left(left_), right(right_), val(val_) {};
};
int main() {
std::shared_ptr <MyTree> t(
new MyTree( std::shared_ptr <MyTree>(),
std::shared_ptr <MyTree>(),
0)
);
for(int i=0;i<10000;i++) {
t.reset(new MyTree(t,t,0));
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当for循环从10000更改为100000时,我收到段错误.查看gdb中的结果,看起来像std :: shared_ptr中的垃圾收集调用的析构函数会创建一个数千深的回溯.因此,我认为段错是由于函数调用从堆栈中耗尽.我有两个问题.首先,这是对segfault的正确评估吗?其次,如果是这样,是否有一种很好的方法来管理自定义数据结构,例如需要进行垃圾回收的树,但可能非常大.谢谢.
我看到了几个不同的研究小组,至少有一本关于使用Coq设计认证程序的书.关于认证计划的定义是什么,是否有共识?从我所知道的,它真正意味着该程序被证明是完整的并且类型正确.现在,程序的类型可能是非常奇特的东西,例如列表,其中包含非空的证明,排序,所有元素> = 5等等.但是,最终,是一个经过认证的程序,Coq显示的是总计和类型安全的程序,所有有趣的问题归结为最终类型中包含的内容?
根据wjedynak的回答,我看了Xavier Leroy的论文"现实编译器的形式验证",它在下面的答案中有所联系.我认为这包含一些很好的信息,但我认为这个研究序列中的信息量更多的信息可以在Sandrine Blazy和Xavier Leroy 的C语言的Clight子集的机械化语义学中找到.这是"形式验证"论文添加优化的语言.在其中,Blazy和Leroy介绍了Clight语言的语法和语义,然后在第5节讨论了这些语义的验证.在第5节中,列出了用于验证编译器的不同策略,这在某种意义上提供了概述创建认证计划的不同策略.这些是:
在任何情况下,可能会添加一些点,我当然希望听到更多.
回到我关于认证程序定义的原始问题,对我来说仍然有点不清楚.Wjedynak提供了一个答案,但Leroy的工作实际上涉及在Coq中创建编译器,然后在某种意义上证明它.从理论上讲,它现在可以证明C程序的内容,因为我们现在可以进行C-> Coq->证明.从这个意义上讲,似乎就是我们可以做到这一点
或者,我们可以在校对助手工具中创建程序规范,然后证明规范的属性,而不是程序本身.
无论如何,如果有人有这些定义,我仍然有兴趣听取其他定义.
我在生成构建设置时遇到问题,该构建设置允许分别使用gcc和MinGW在Linux和Windows中构建共享库.在Linux中,共享库不必在编译时解析所有依赖项; 然而,在Windows中出现这种情况.这是问题设置:
$ cat foo.h
#ifndef FOO_H
#define FOO_H
void printme();
#endif
Run Code Online (Sandbox Code Playgroud)
$ cat foo.c
#include "foo.h"
#include <stdio.h>
void printme() {
printf("Hello World!\n");
}
Run Code Online (Sandbox Code Playgroud)
$ cat bar.h
#ifndef BAR_H
#define BAR_H
void printme2();
#endif
Run Code Online (Sandbox Code Playgroud)
$ cat bar.c
#include "bar.h"
#include "foo.h"
void printme2() {
printme();
printme();
}
Run Code Online (Sandbox Code Playgroud)
$ cat main.c
#include "bar.h"
int main(){
printme2();
}
Run Code Online (Sandbox Code Playgroud)
$ cat Makefile
.c.o:
gcc -fPIC -c $<
all: foo.o bar.o main.o
gcc -shared foo.o -o libfoo.so
gcc -shared bar.o -o libbar.so
gcc …Run Code Online (Sandbox Code Playgroud) 以下代码在gcc 4.9.3和clang 3.7.1上编译并运行得很好
// std::unique_ptr
#include <memory>
// Template class for template-template arguments
template <typename Real>
struct Bar {};
// Base class
template <typename T,template <typename> class XX>
struct Base {};
// Derived class that operates only on Bar
template <typename Real>
struct Derived : public Base <Real,Bar> {};
// Holds the unique_ptr
template <typename T,template <typename> class XX>
struct Foo {
std::unique_ptr <Base <T,XX>> foo;
};
// Create an alias template
template <typename Real>
using Buz = Bar <Real>; …Run Code Online (Sandbox Code Playgroud) 你如何使用GADT在OCaml中定义一个简单的lambda演算类DSL?具体来说,我无法弄清楚如何正确定义类型检查器以从无类型的AST转换为类型化的AST,也无法找出上下文和环境的正确类型.
下面是一些使用OCaml中传统方法的简单lambda演算语言的代码
(* Here's a traditional implementation of a lambda calculus like language *)
type typ =
| Boolean
| Integer
| Arrow of typ*typ
type exp =
| Add of exp*exp
| And of exp*exp
| App of exp*exp
| Lam of string*typ*exp
| Var of string
| Int of int
| Bol of bool
let e1=Add(Int 1,Add(Int 2,Int 3))
let e2=Add(Int 1,Add(Int 2,Bol false)) (* Type error *)
let e3=App(Lam("x",Integer,Add(Var "x",Var "x")),Int 4)
let rec typecheck con e …Run Code Online (Sandbox Code Playgroud)