小编0xb*_*00d的帖子

C++ char16_t的大小取决于什么?

这也char32_t和任何有关intXX_t.规范指出:

2.14.3.2:

包含单个c-char的char16_t文字的值等于其ISO 10646代码点值,前提是代码点可用单个16位代码单元表示.

5.3.3.1:

[..]特别是[...] sizeof(char16_t),sizeof(char32_t)和sizeof(wchar_t)是实现定义的

intXX_t除了评论它们是"可选的"(18.4.1)之外,我看不出有关类型的任何信息.

如果不char16_t保证是2个字节,那么它是否保证是16位(即使在1个字节的架构上!= 8位)?

c++ c++11 char16-t char32-t

12
推荐指数
2
解决办法
1739
查看次数

OpenGL - How to access depth buffer values? - Or: gl_FragCoord.z vs. Rendering depth to texture

I want to access the depth buffer value at the currently processed pixel in a pixel shader.

How can we achieve this goal? Basically, there seems to be two options:

  1. Render depth to texture. How can we do this and what is the tradeoff?
  2. Use the value provided by gl_FragCoord.z - But: Is this the correct value?

opengl shader glsl fragment-shader

10
推荐指数
2
解决办法
2万
查看次数

实体框架4.1代码创建多对多关系的第一种方法

我在Silverlight应用程序中使用Silverlight 5 Beta SDK和EntityFramework 4.1.

我将尝试创建两个表'Author'和'Book'.在SQL中,应该有第三个(连接)表,它在Author和Book之间建立多对多关系(一个作者可以编写很多书,一本书可以从许多作者那里编写).

这是我到目前为止所得到的:

namespace CodeFirst.Models.Web
{    
    public class Author
    {
        public Author()
        {
            this.Books = new HashSet<Book>();
        }

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Key]
        public int ID { get; set; }

        [Required]
        public string Name { get; set; }

        public ICollection<Book> Books { get; set; }
    }


    public class Book
    {
        public Book()
        {
            this.Authors = new HashSet<Author>();
        }


        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Key]
        public int ID { get; set; }

        [Required]
        public string Name { get; set; }

        public ICollection<Author> Authors { …
Run Code Online (Sandbox Code Playgroud)

c# silverlight many-to-many code-first entity-framework-4.1

9
推荐指数
1
解决办法
3127
查看次数

空数组声明 - 奇怪的编译器行为

我在一个我必须维护的项目中发现了一段奇怪的代码.有一个类的空数组成员,不会导致编译器错误.我已经使用MSVC 10.0测试了这些代码的一些变体:

template<class T> struct A {
    int i[];
}; // warning C4200: nonstandard extension used : zero-sized array in struct/union

template<class T> struct B { static int i[]; };
template<class T> int B<T>::i[];

struct C {
    int i[];
}; //warning C4200: nonstandard extension used : zero-sized array in struct/union

template<class T> struct D { static int i[]; };
template<class T> int D<T>::i[4];
template<>        int D<int>::i[] = { 1 };


int main()
{
    A<void> a;
    B<void> b;
    C c;
    D<void> …
Run Code Online (Sandbox Code Playgroud)

c++ arrays standards

9
推荐指数
1
解决办法
1901
查看次数

我们可以在noexcept规范中引用成员变量吗?

请考虑以下代码段:

template<class Tuple>
class vector
{
public:
    typename Tuple::size_type size() const noexcept(noexcept(m_elements.size())) {
        return m_elements.size();
    }

private:
    Tuple m_elements;
};

class tuple
{
public:
    using size_type = std::size_t;

    size_type size() const { return 0; }
    size_type size() noexcept { return 0; }
};    

int main()
{
    vector<tuple> x;
    static_assert(noexcept(x.size()), "x.size() might throw");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

m_elements在说明noexcept符中使用成员变量是合法的吗?GCC 5.2(C++ 17)产生的编译器错误 m_elements未在此范围内声明.而clang 3.6(C++ 17)编译时没有任何错误.

如果我改用,两个编译器都不会产生错误noexcept(std::declval<Tuple const&>().size()).但是,正如您所看到的,我创建了一个简单的示例类tuple,无论是否Tuple具有合格的重载都至关重要size.

从我的角度来看,它更直观, …

c++ language-lawyer noexcept c++14 c++17

9
推荐指数
1
解决办法
440
查看次数

实体框架| 代码优先 - 获取创建表的名称

可能吗?当我指定TableAttribute时,我知道我可以获得名称,但是当我让框架管理名称时,它应该是可能的.

提前致谢.

entity-framework code-first entity-framework-4 entity-framework-4.1

8
推荐指数
2
解决办法
3420
查看次数

C++什么时候我们更喜欢在reinterpret_cast上使用两个链式的static_cast

首先,这不是重复的为什么当两个链接的static_cast可以完成它的工作时,我们在C++中有reinterpret_cast?.

我知道我们甚至不能使用两个连锁static_cast来实现这reinterpret_cast一点的情况.但是,在任何情况下我都应该选择两个链接static_cast而不是简单且更具可读性的情况reinterpret_cast吗?

c++ casting static-cast reinterpret-cast

8
推荐指数
3
解决办法
1065
查看次数

basic_streambuf :: seekoff当ios_base :: in |时应该返回什么 是否指定了ios_base :: out?

27.6.3.4.2缓冲区管理和定位

pos_type seekoff(off_type off, ios_base::seekdir way,
    ios_base::openmode which = ios_base::in | ios_base::out);
Run Code Online (Sandbox Code Playgroud)
  • 效果:以一种basic_streambuf为本条款(27.8.2.4,27.9.1.5)中派生的每个类别单独定义的方式改变一个或多个受控序列中的流位置.
  • 默认行为:返回pos_type(off_type(-1)).

到现在为止还挺好.basic_streambuf我正在使用的派生可以单独改变其位置ios_base::in和/或ios_base::out.但是,当指定两者时,我需要返回什么?

如果指定ios_base::in or ios_base::out,我们将返回特定序列的新流位置.

c++ iostream streambuf

8
推荐指数
1
解决办法
287
查看次数

更改Geocoder.geocode()返回结果的语言

正如API参考声明:

The Geocoding API defines a geocoding request using the following URL parameters:

 - language (optional) — The language in which to return results. See the supported list of domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the geocoder will attempt to use the native language of the domain from which the request is sent wherever possible.
Run Code Online (Sandbox Code Playgroud)

但是,指定language参数似乎没有效果(使用Firefox 8,IE 9和Chrome 15测试).

new google.maps.Geocoder().geocode({ …
Run Code Online (Sandbox Code Playgroud)

javascript google-maps google-maps-api-3

8
推荐指数
1
解决办法
1万
查看次数

使用标准库切片

标准库中是否有一个功能允许我切片std::slice或者我需要编写类似的东西

std::slice refine(std::slice const& first, std::slice const& second)
{
    return {
        first.start() + second.start() * first.stride(),
        second.size(),
        first.stride() * second.stride()
    };
}
Run Code Online (Sandbox Code Playgroud)

我自己?

c++ slice valarray c++14

8
推荐指数
1
解决办法
713
查看次数