小编Mat*_*son的帖子

CSS:not(:last-child):选择器之后

我有一个元素列表,其样式如下:

ul {
    list-style-type: none;
    text-align: center;
}

li {
    display: inline;
}

li:not(:last-child):after {
    content:' |';
}
Run Code Online (Sandbox Code Playgroud)
<ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li>Four</li>
    <li>Five</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

输出One | Two | Three | Four | Five |而不是One | Two | Three | Four | Five

任何人都知道如何选择CSS除了最后一个元素?

您可以在此处查看:not()选择器的定义

css css-selectors pseudo-element

344
推荐指数
6
解决办法
48万
查看次数

在Enum中搜索字符串并返回Enum

我有一个枚举:

public enum MyColours
{
    Red,
    Green,
    Blue,
    Yellow,
    Fuchsia,
    Aqua,
    Orange
}
Run Code Online (Sandbox Code Playgroud)

我有一个字符串:

string colour = "Red";
Run Code Online (Sandbox Code Playgroud)

我希望能够回归:

MyColours.Red
Run Code Online (Sandbox Code Playgroud)

从:

public MyColours GetColour(string colour)
Run Code Online (Sandbox Code Playgroud)

到目前为止,我有:

public MyColours GetColours(string colour)
{
    string[] colours = Enum.GetNames(typeof(MyColours));
    int[]    values  = Enum.GetValues(typeof(MyColours));
    int i;
    for(int i = 0; i < colours.Length; i++)
    {
        if(colour.Equals(colours[i], StringComparison.Ordinal)
            break;
    }
    int value = values[i];
    // I know all the information about the matched enumeration
    // but how do i convert this information into returning a
    // …
Run Code Online (Sandbox Code Playgroud)

c# string enumeration

148
推荐指数
4
解决办法
11万
查看次数

Javascript枚举到对应的字符串值

所以我在我的页面的javascript中有这个:

var TEST_ERROR  = {
        'SUCCESS'   :   0,
        'FAIL'      :   -1,
        'ID_ERROR'  :   -2
      };
Run Code Online (Sandbox Code Playgroud)

并对页面中的函数执行测试,如下所示:

function test()
{
    // Get the paragraph from the DOM
    var testResultParagraph = document.getElementById('testResult');

    // Check the paragraph is valid
    if(!testResultBox)
    {
        // Update the web page
        testResultParagraph.value = TEST_ERROR.ID_ERROR;
        return TEST_ERROR.ID_ERROR;
    }

    // Something to store the results
    var testResult = TEST_ERROR.SUCCESS;

    // Test the calculation
    testResult = testCalculate()

    // Update the web page
    testResultParagraph.value = testResult;

    // The test succeeded
    return TEST_ERROR.SUCCESS; …
Run Code Online (Sandbox Code Playgroud)

javascript enums

26
推荐指数
4
解决办法
6万
查看次数

为什么emplace_back需要移动构造函数

我有以下代码:

#include <string>
#include <vector>
#include <iostream>

class Test final {
public:
  Test(const std::string& s)
    : s_(s) {
    std::cout << "constructing: " << s_ << std::endl;
  }
#ifdef NO_MOVE
private:
  Test(const Test& t) = delete;
  Test(Test&& t) = delete;
#else
public:
  Test(const Test& t)
    : s_(t.s_) {
    std::cout << "copying: " << s_ << std::endl;
  };
  Test(Test&& t)
    : s_(std::move(t.s_)) {
    std::cout << "moving: " << s_ << std::endl;
  };
#endif
private:
  std::string s_;
};

int main() {
  std::vector<Test> v; …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

17
推荐指数
1
解决办法
5829
查看次数

std :: hash保证在stdlib发行版中是相同的

如果我std::hash使用了libstdc++,然后在即将推出的C++11VS 2012库中做了一个- 它们会匹配吗?

我假设哈希实现不是C++规范的一部分,可以根据分布而变化?

c++ hash c++11 stdhash

10
推荐指数
3
解决办法
508
查看次数

在类上启用std :: get支持

我必须专门支持std :: get的模板是什么?

struct MyClass {
  int a;
};

template <const size_t I>
struct MyContainer {
  MyClass array[I];
};
Run Code Online (Sandbox Code Playgroud)

我有什么专业能够做到的:

MyContainer<16> mc;
std::get<0>(mc);
Run Code Online (Sandbox Code Playgroud)

c++ c++11 stdtuple

10
推荐指数
1
解决办法
2243
查看次数

获取当前的GCC异常模型

g++使用无论是建DWARF2,sjljseh异常模型. MinGW-builds提供g++具有不同异常模型的各种构建.我希望能够从gcc工具链中确定正在使用的异常模型.是否有一个g++参数将转储编译器的默认异常模型?

gcc mingw-w64

10
推荐指数
1
解决办法
2544
查看次数

吞噬功能之外的分号的宏

在函数外面的cpp宏之后是否有任何强制分号的成语?

用于内部函数的宏的已知解决方案是:

#define MACRO(x) \
  do {
    x * 2;
  } while(0)
Run Code Online (Sandbox Code Playgroud)

但是,假设我有一个如下所示的宏:

#define DETAIL(warning) _Pragma(#warning)
#define WARNING_DISABLE(warning) DETAIL(GCC diagnostic ignore warning)
Run Code Online (Sandbox Code Playgroud)

我可以在宏中强加一个在该语句后强制分号的内容.该语句可以在函数内部或外部使用:

WARNING_DISABLE("-Wunused-local-typedefs")
#include "boost/filesystem.hpp"
void foo(const int x) {
    WARNING_DISABLE("-Wsome-warning")
    ...
}
Run Code Online (Sandbox Code Playgroud)

是否有任何C/C++语法会在文件中任何没有副作用的位置强制解析器中出现分号?

编辑:一个可能的用例:

#define MY_CPPUNIT_TEST_SUITE(test_suite_class) \
  WARNING_PUSH \
  /* the declaration of the copy assignment operator has been suppressed */ \
  INTEL_WARNING_DISABLE(2268) \
  /* the declaration of the copy assignment operator has been suppressed */ \
  INTEL_WARNING_DISABLE(2270) \
  /* the declaration of the copy constructor operator …
Run Code Online (Sandbox Code Playgroud)

c c++ c-preprocessor

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

const数组const {}

所以你可以这样做:

void foo(const int * const pIntArray, const unsigned int size);
Run Code Online (Sandbox Code Playgroud)

这表示指针是只读的,它指向的整数是只读的.

您可以像这样访问函数内部:

blah = pIntArray[0]
Run Code Online (Sandbox Code Playgroud)

您还可以执行以下声明:

void foo(const int intArray[], const unsigned int size);
Run Code Online (Sandbox Code Playgroud)

它几乎相同,但你可以这样做:

intArray = &intArray[1];
Run Code Online (Sandbox Code Playgroud)

我可以写:

void foo(const int const intArray[], const unsigned int size);
Run Code Online (Sandbox Code Playgroud)

那是对的吗?

c const c99

7
推荐指数
1
解决办法
1717
查看次数

媒体查询以横向模式区分桌面和iPad

我正在建立一个响应式设计的网站.我需要区分横向模式下的平板电脑和带有媒体查询的桌面之间的布局.这些是媒体查询:

<link href="base.css" rel="stylesheet"/>
<link href="desktop.css" 
media="only screen and (min-width: 801px)" rel="stylesheet"/>
<link href="tablet.css" 
media="only screen and (min-width: 629px) and (max-width: 800px) and 
(orientation:portrait), 
only screen and (min-height:629px) and (max-height:800px) and 
(orientation:landscape)" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)

desktop.css在横向模式下,平板电脑包含问题.iPad在风景中很1024px广泛,这是PC的常见解决方案.如何通过媒体查询将1000px横向模式中的宽dekstop与平板电脑区分开来?

PS我必须使用媒体查询,因为网站将被缓存/ CDNed等.任何服务器端检测都不起作用.

PS2.

<link href="desktop.css" 
media="only screen and (min-width: 801px), 
not only screen and (min-height:629px) and (max-height:800px) and 
(orientation:landscape)" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)

没有解决问题.

css3 media-queries

7
推荐指数
1
解决办法
9277
查看次数