A list of puns related to "Const"
Some new Svelte features were just released:
- style directives, e.g. style:color are a nice syntactic sugar for setting dynamic inline styles (REPL, docs)
- the @βconst tag lets you define constants in your template (REPL, docs)
I'm excited to start using these! Check out the linked PRs and RFCs in the changelog for more info and background.
Itβs just confusing. I mean, βconstβ doesnβt distinguish them from regular generics: Rust is statically typed, so types are also const
-evaluated. Why isnβt it βvalue genericsβ or something?
Compare to βnon-type template parametersβ in C++.
I have a program where I have included a file with embedFile. I create some tokens with std.mem.tokenize() and start to iterate over them:
while (it.next()) |line| {
var foo: []u8 = line;
}
This part fails, as line is a []const u8. I have watched a video from Loris Cro (https://www.youtube.com/watch?v=VgjRyaRTH6E) where he states that You should not use []u8 when You do not want to modify the slice, but I do want to modify it (want to call std.sort.sort() later on). How can I convert these types? I just can not figure it out.
Edit: Meanwhile I have found this: https://www.reddit.com/r/Zig/comments/jwdm50/comment/gcpn447/?utm_source=share&utm_medium=web2x&context=3
So I understand that converting does not work, but Coule I create a copy of the immutable string to my mutable variable?
Just something that bothers me running tank. I get tossed around everywhere and constantly stunned or blown over (blocking or not).
So, I keep reading that const methods are thread-safe by default.
Can someone elaborate if this is the case, because I don't really see how this can be the case, unless there is an "in the absence of writes" implied (however with no writes, everything is thread-safe).
Sometimes I find these kinds of types in function signatures:
fn myMfunction(..., a: *const *const u8, ...) { ...}
My question is: what is the meaning of these "double const"? What is the interest to have a pointer towards a pointer? Does it serve any purpose, especially in the context of FFI?
Also is this the best way to implement Array?
#if __cplusplus>=201703L
# define CONSTEXPR17 constexpr
#else
# define CONSTEXPR17
#endif
size_t m_len;
E* m_ptr;
// ...
template <typename E>
Array<E>::Array(const std::initializer_list<E>& list) noexcept :
m_len(list.size()),
m_ptr(m_len == 0 ? nullptr
: reinterpret_cast<E*>(std::malloc(sizeof(E) * m_len)))
{
if (m_ptr) {
if CONSTEXPR17 (std::is_class<E>::value)
{
E* it = const_cast<E*>(list.begin()); // <<<<--------
if(it) {
if CONSTEXPR17 (std::is_move_constructible<E>::value)
for(size_t i=0; i<m_len; ++i)
new (m_ptr + i) E(std::move(it[i])); // move
else
for(size_t i=0; i<m_len; ++i)
new (m_ptr + i) E(it[i]); // copy
}
}
else
{
const E* it = list.begin();
if(it)
for(size_t i=0; i<m_len; ++i)
m_ptr[i] = it[i];
}
}
else m_len = 0;
}
Array code (no Tracer): https://godbolt.org/z/W8fcb1xo4
Array code + Tracer + tests: https://godbolt.org/z/PWf6Monjh
sample code:
template <typename E>
class Array
{
public:
CONSTEXPR11 static const bool Is_Elem_Class = IFCXX11ELSE(std::is_class<E>::value, true);
CONSTEXPR11 static const bool Is_Elem_Default_Constructible = IFCXX11ELSE(std::is_default_constructible<E>::value, true);
CONSTEXPR11 static const bool Is_Elem_Destructible = IFCXX11ELSE(std::is_destructible<E>::value, true);
CONSTEXPR11 static const bool Is_Elem_Copy_Constructible = IFCXX11ELSE(std::is_copy_constructible<E>::value, true);
CONSTEXPR11 static const bool Is_Elem_Move_Constructible = IFCXX11ELSE(std::is_move_constructible<E>::value, false);
CONSTEXPR11 static const bool Is_Elem_Copy_Assignable = IFCXX11ELSE(std::is_copy_assignable<E>::value, true);
CONSTEXPR11 static const bool Is_Elem_Move_Assignable = IFCXX11ELSE(std::is_move_as
... keep reading on reddit β‘I'm totally new to svelte.Can someone give me a usecase for readonly properties?
// HelloWorld.svelte
<script>
// these are readonly
export const myProp = 'readonly';
</script>
<div>{myProp}</div> // Will always show 'readonly'
Assigning a property during component declaration as follows has no effect:
<HelloWorld myProp="some value"/>
The value "some value" gets ignored. Had I used let
instead, this would work.So when does declaring property with export cons
t become useful?
EDIT: Updated the example according to u/venir_dev's comment to make the example more reasonable.
I have a rather extensive experience in both C and C++ and I will be glad for getting some help in what kind of values the type described in the title can hold and getting some example values of that type.
Specifically I am trying to call the Linux ls command from a Zig program using the function std.os.execvpeZ described here:
https://github.com/ziglang/zig/blob/a5c7742ba6fc793608b8bb7ba058e33eccd9cfec/lib/std/os.zig#L1642
Using both null arguments and other string arguments.
Note: I already know that [*:0]const u8 is equivalent to a C null terminated string.
Thanks.
Why const reference over a normal int variable decleration in this parameter list?
int max(const int& num1, const int& num2)
{
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
Hi! I'm looking for some best practices here.
I have a pretty big const library in ES node, which is shared between all components of my application. About 7 or 8. The const library has between 50-100 consts and is updated regularly.
Its basically a long list of this:
const SHAPETYPE = {
CIRCLE: 1,
RECTANGLE: 2,
}
export { SHAPETYPE }
In code, all we use is SHAPETYPE.CIRCLE etc, but under the hood all that is passed around and stored in databases is the int value.
I need to access this library in rust. What would be a good way to do this without having to redefine the whole library?
One solution that I thought is to write a parser program that converts the library to rust enums, which would then be available in the code. Would this be the way to go?
Thanks!
Lets say I have colors.zig file with something like this:
const RGB8 = @import("color.zig");
pub const red = RGB8.init(255, 0, 0);
pub const green = RGB8.init(0, 255, 0);
pub const blue = RGB8.init(0, 0, 255);
pub const yellow = RGB8.init(255, 255, 0);
// ...
// Can I somehow generate an array of all defined colors:
pub const all = [_]RGB8 { GET_ALL_DEFINED_COLORS_FROM_ABOVE_SOMEHOW };
// Also can I get a list of color names in the same order:
pub const names = [_][_]u8 { GET_ALL_DEFINED_COLOR_NAMES_FROM_ABOVE_SOMEHOW };
I'm brand new to elixir, just started a course. Very early in it. I could be patient and wait to be taught more stuff, but where's the fun in that? Lol
I love the immutable design of elixir data structures. However it seems like an issue where you can reassign a variable. Other languages have constructs like Val/const/final that prevent this. Is there something like this in elixir?
Thanks.
I recently had a discussion with one of my co-workers where the intent was to have one aspect of a class that was shared across all objects. By definition, this is a static
member variable.
However, a good point was raised in this discussion. If you have a const
member (let's say a value, i.e. not pointer or reference), wouldn't it make sense for the compiler to make this static
? It seems wasteful for each object to hold something like this.
Is there reasoning why const
members aren't treated as static
class members?
I'm a relatively low-spender/f2p buying only daily chests, seasonal bundles for the most part. I'm just finishing KVK3 and have Alex, YSG, and CM expertised; Sala 5/5/5/2 and Richard 5/5/1/1. He just became available through Daily Chests and my options are to either purchase Sala and over time expertise him, or purchase Const for the foreseeable future.
I dont plan on using many, if any, heads to get him 5/5/1/1 since SOC commanders will become available. But some say he isnt worth it at all
Just as a summary (from local news source):
I'm not sure what exactly the breakdown was (which D's voted Yay), as the PA site doesn't seem to have it by Party. I am curious what counties they represent though. Does anyone else think that it's odd? Or just a fluke?
Senate: https://www.legis.state.pa.us/CFDOCS/Legis/RC/Public/rc_view_action2.cfm?sess_yr=2021&sess_ind=0&rc_body=S&rc_nbr=361
House: https://www.legis.state.pa.us/CFDOCS/Legis/RC/Public/rc_view_action2.cfm?sess_yr=2021&sess_ind=0&rc_body=H&rc_nbr=624
Please help me sort this mess :)
I'm trying to make this work, since I'm a NodeN00b I'd really appreicate a heads up.
My co-worked has created a monsterfile filled with functions, loaded via
index.js
const x = require(file);
I have another helper function file i call like this:
const helper = require('../helper');
const helperFunc = new helper(VARS, x);
helper.js
class Helper {
constructor(VARS, x) {
this._VARS = VARS;
this._x = x;
}
static get VARS() {
return this._VARS;
}
static get x() {
return this._x;
}
needed() {
const newTopic = x.topicFunctionInX(
VARS.param,
name
);
}
}
Thing is, I need the functions from x, to also be available in my helper file.
Everything that is related to x in my sample is a mystery to me. Anybody care to point me in the right direction?
Today I was implementing my new const generic structure HeightMap:
impl HeightMap<const HEIGHT: usize, const WIDTH: usize>
But of course that's wrong, you can't do that. Rust's compiler (1.56.1) said:
error: expected one of `>`, a const expression, lifetime, or type, found keyword `const`
... which is true but unhelpful, particularly because "Huh, const isn't a const expression?" doesn't promote healthy thinking about what's wrong here.
In fact what I should write is:
impl<const HEIGHT: usize, const WIDTH: usize> HeightMap<HEIGHT, WIDTH>
It would be nice if the Rust compiler suggested I try that, or at least something closer to that, in this sort of case rather than waiting until I realize for myself.
I don't know how to go about making such a change, if it's easy maybe I should learn how.
I lived in Playa for a few months a while ago and use to go out in the area of 5th and Constituyentes because it seemed well populated and safe. I've been back this week and have seen a violent ruckus at a bar named Bloody Mary twice in one week, both involving the owner. Never a cop around. Is this normal for that area now? If it were once I wouldn't think twice but it's been twice in one week at the same bar. Is that area desinigrating? Is it normal for that bar?
I've been using Dart for a few months now and I'm really bothered by not being able to prevent objects from being modified (like C++ const
) when passed as function parameters.
Let's take this simple example:
class A {
int i = 0;
}
void foo(final A a) {
a.i = 2;
}
void main() {
final a = A();
foo(a);
assert(a.i == 2);
}
I'd like to ensure that foo
keeps parameter 'a' unchanged, ideally detected at compile time.
Am I missing a keyword or a solution? Or is it not supposed in Dart?
say there's a const fn that takes an i32 as parameter then return the input parameter squared, but depending on certain condition I want to just fail to compile
const fn foo(num: i32) -> i32 {
if some_condition {
fail_to_compile
} else {
num * num
}
}
in c++ if you do anything that's invalid in constant evaluated context (like throwing an exception), the compiler will scream at you but only if the control flow reaches said invalid operation, for example:
// this code will compile just fine
// because the control flow won't reach
// the "throw" line
consteval int foo(int num) {
if (false) {
throw 0xDEADBEEF;
} else {
return num * num;
}
}
I'm looking for the same behavior in rust, is it possible?
You haven't changed a bit.
Are there any drawbacks to it?
What should I keep in mind except for the size of an object before using const references?
So when should I use each type of variable? Can someone explain in a sentence ? I feel confused and choose them randomly.
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.